Hi, in my game I use procedural generation to create my levels and I was thinking on using additive scenes for when the player enters in a room. That way, the room loads seamlessly and the player can enter to the room and when he leaves it, the level is still there. If I load and unload the scene with the main level, it will be different as it gets generated on the fly.
The issue I’m having is I want the room to hide the content of the level but I can’t really hide an scene, I have to unload it (which I’m trying to avoid). By the other hand, another solution could be using a different camera, but that means I have to duplicate layers for elements such as obstacles for example, to be able to render each obstacle in its camera.
Any idea to accomplish something like this?
Thanks so much!
@danimarti Hope this doesn’t count as a necro - the question is at the top of the Google results when I searched for it.
I had a similar requirement, where I needed a persistent “world map”, and then “rooms” that the player can go into, which are loaded on the fly.
So I parented my entire “world map” to a single object, and simply disabled that object. The lighting etc was outside the world, so that was all preserved. And likewise, returning was simply a case of unloading the room and then re-enabling the world-map parent.
Imma just dump my class here (as it is also responsible for disabling the audio listener on the world-map camera):
public class GameManager : MonoBehaviour
{
public WorldMap WorldMap;
private bool InWorldMap => WorldMap.gameObject.activeInHierarchy;
private void Start()
{
Application.targetFrameRate = 60;
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.Return))
{
if (InWorldMap)
{
GotoTactical();
}
else
{
ReturnToWorld();
}
}
}
private void GotoTactical()
{
WorldMap.DisableAudioListener();
var operation = SceneManager.LoadSceneAsync("Tactical", LoadSceneMode.Additive);
StartCoroutine(WaitForOperation(operation, () =>
{
WorldMap.gameObject.SetActive(false);
}));
}
private void ReturnToWorld()
{
var operation = SceneManager.UnloadSceneAsync("Tactical");
StartCoroutine(WaitForOperation(operation, () =>
{
WorldMap.gameObject.SetActive(true);
}));
}
private IEnumerator WaitForOperation(AsyncOperation operation, Action completion)
{
while (!operation.isDone)
{
yield return null;
}
completion();
}
}