VISU – Looping Backgrounds is a streamlined solution designed to help game developers create endlessly looping backgrounds and foregrounds, enhancing immersion in 2D games. With this asset, you can achieve fluid, continuous movement in your scenes, adding depth and dynamism. Ideal for endless runners, platformers, side-scrollers, and racing games, this tool saves hours of work by providing a plug-and-play looping background system.
Add VISU – Looping Backgrounds to your project and let players enjoy a seamless visual experience as your scenes extend beyond the screen!
—> [Download here (Unity Asset Store link)]
Version History
- Version 1.0 – November 2024
Components
- Scripts
- VisuLoopingScript.cs – Manages and positions looping backgrounds and foregrounds.
- VisuCameraFollow.cs – Camera Follow script
- PlayerScript.cs – Simple player movement script for the demo
- Custom Editor Scripts
- VisuLoopingEditor.cs – Custom editor for the Looping Manager.
- VisuCameraEditor.cs – Custom editor for the Camera Follow script.
- Prefabs
- Scenario Prefab – Collection of backgrounds and foregrounds for the demo.
- Variants Examples – Some variations on the previous Scenario prefabs to show the variant functionality.
- Player Prefab – Simple player little fella for the demo.
- Scenes
- Visu – Demo Looping Backgrounds
Installation
To install VISU – Looping Backgrounds in your Unity project:
- Download: Obtain the VISU – Looping Backgrounds package from the Unity Asset Store.
- Import: Open your Unity project. Go to
Assets > Import Package > Custom Package
, select VISU – Looping Backgrounds, and click Open. - Configuration:
- Attach VisuCameraFollow.cs to your camera and assign Player and Camera in the inspector. (Note: The looping should work with other Camera Follow scripts of your choice.)
- Attach the VisuLoopingScript.cs component to an empty GameObject. This will be our Looping Manager.
- Make sure the VisuLoopingEditor.cs is in your project’s Editor folder.
- In the Looping Manager Settings tab in the inspector, assign the Player and Camera. Enable Looping.
- In the Looping Manager Layers tab in the inspector, assign each one of the objects you would like to see looping. Works with colliders as well.
- Tip:
- More Settings (Optional):
- You can choose if each layer should repeat on X or Y axis (or both).
- Enable Variants for multiple objects alternating on a single flow (read more below)
- Choose the size of the thumbnails in inspector: Big, Small or No Preview.
- All done!
- Enjoy beautiful seamless looping backgrounds! You just saved several hours if not days of work.
Variants
Enable Variants in the Settings tab and assign them on the Layers tab. This will make the script instantiate any of the objects assigned within a given layer (variants + original).
This feature is called by this method of VisuLoopingScript.cs:
private GameObject PickVariant(GameObject[] allObjects)
{
// Choose a random index if variants are enabled, otherwise select the first object (index 0).
int index = useVariants ? UnityEngine.Random.Range(0 , allObjects.Length) : 0;
return allObjects[index];
}
If you are into coding, this method can be changed into any other logic you’d like, by adding conditionals to return different “index” results.
Here is another example that would get you always the next object on the list:
private int currentIndex = 0; // Tracks the current position in the array
private GameObject PickVariant(GameObject[] allObjects)
{
// If variants are enabled, pick the next object in sequence.
if (useVariants)
{
// Get the current object, then increment the index for the next call
GameObject selectedObject = allObjects[currentIndex];
// Move to the next index, wrapping back to 0 if we reach the end of the array
currentIndex = (currentIndex + 1) % allObjects.Length;
return selectedObject;
}
else
{
// If variants are not enabled, always return the first object
return allObjects[0];
}
}
Usage Examples
Use VISU – Looping Backgrounds to create various 2D game scenarios, such as:
- Endless Runners: Seamlessly loop environments to keep the action going.
- Side-Scrollers: Or any 2D Platformer, really
- Racing Games: Create dynamic scenes that evolve as the player moves.
Did you use Visu in your project? Contact me to be featured here.
Troubleshooting
- Camera Not Following the Target:
- Ensure that the Target GameObject is assigned correctly to the VisuCameraFollow component.
- Verify that the Camera is correctly assigned to the VisuCameraFollow component.
- Jittery or Erratic Camera Movement:
- Adjust the damping settings in the VisuCameraFollow component to smoothen the camera movement.
- Ensure that there are no sudden changes in the target’s position that could cause jittery movement.
- Maybe the issue is with your player. If its movement uses Rigidbody, make sure the Rigidbody interpolation is set to Interpolate.
Player:
- Player falling through terrain
- Make sure the player has a Collider2D component. Make sure the terrain has a Collider2D component as well.
- Player not jumping
- In the PlayerScript settings, assign a Ground Layer for the player to detect. Go to the ground/terrain object inspector and make sure it is assigned the same Ground Layer
- Verify the jump force value in the Player inspector.
- Note: the player is not a looping layer, no need to assign it in the Looping Manager’s layers.
Looping:
- Layer not looping:
- Check if Looping is enabled in Settings tab
- Check if that individual layer’s loop options are enabled in the Layers tab
- Where are my original objects?
- The original objects and their variants are moved far far away (X: 20000f, Y: -20000, top left) at starting the scene. This is pseudo-pooling option so they don’t disrupt gameplay.
- How many objects can it handle?
- The asset was created with only a few objects in mind, the limits were not tested. As a general suggestion, you can group several objects and make them loop in chunks, or even as a single object. This is demonstrated by the Clouds prefab of the Demo scene, which is made of several different clouds.
Variants:
Note: The default behavior is random. This feature is supposed to be customized as seen below.
- Why is one variant showing up more than others?
- There is no need to assign the original object in the Variants list, this could duplicate the chances of it showing up.
- Can I make a variant have more chances of showing up?
- Like above answer, if you want an object to show up more times in relation to the others, just assign it multiple times as a variant.
With VISU – Looping Backgrounds, you can bring your 2D game to life with a continuous and captivating environment!
Thank you!