1
\$\begingroup\$

I want to rebuild the RE4 game behaviour.

In RE4, the inventory screen is a scene of its own.

In Unity, the scenes which are loaded additively inherit the skybox / lights from the first scene loaded.

That is why I start my game with an empty scene without any lights. Else, if I would load the inventory level when it's actually needed, it would inherit the lights from the currently loaded scene.

To avoid this, I have established the following game logic:

The first scene a black scene with just a single, empty gameobject. This gameobject has a script on it that loads the other scenes:

using UnityEngine;
using UnityEngine.SceneManagement;

public class StartupScript : MonoBehaviour
{
    AsyncOperation _InventoryScene;
    AsyncOperation _FirstLevel;

    void Start()
    {
        //load the inventory scene so that we can quickly show it when the user presses the "Inventory" key.
        _InventoryScene = SceneManager.LoadSceneAsync("InventoryScene", LoadSceneMode.Additive);
        _InventoryScene.allowSceneActivation = false; //we make it so that it is not shown

        //Instead, we load the first level
        _FirstLevel = SceneManager.LoadSceneAsync("Level1Scene", LoadSceneMode.Additive);
        _FirstLevel.allowSceneActivation = true;//start the game by showing Level 1 scene
    }
}

For some reason however, Unity does not show the level. Instead, both scenes stay at "(is loading)".

enter image description here

What am I missing?

Thank you!

Edit: When I do not load the InventoryScene first, the Level scene loads without any problems.

Edit2: When I load the InventoryScene at last, the InventoryScene stays at "(is loading)".

enter image description here

\$\endgroup\$
5
  • \$\begingroup\$ Does it load eventually or not at all? \$\endgroup\$ Commented Jul 26, 2021 at 20:10
  • \$\begingroup\$ When I set the first scene to allowSceneActivation = false;, the subsequent scene is also not loaded at all. \$\endgroup\$
    – tmighty
    Commented Jul 26, 2021 at 21:53
  • \$\begingroup\$ Are there any errors or warnings in the Unity console? \$\endgroup\$
    – Philipp
    Commented Jul 27, 2021 at 11:53
  • \$\begingroup\$ @Philipp Not at first, but I do remember that I left the game in this state for quite some time, and then at some point it did show an error message, but I don't remember which. \$\endgroup\$
    – tmighty
    Commented Jul 29, 2021 at 21:33
  • \$\begingroup\$ Is there a particular reason why you would prefer to have the inventory be it's own scene rather than full screen UI? Also, lighting and skybox settings are from the active scene, not necessarily the first. \$\endgroup\$ Commented Jul 30, 2021 at 2:47

1 Answer 1

2
\$\begingroup\$

The documentation for allowSceneActivation reads:

When allowSceneActivation is set to false, Unity stops progress at 0.9, and maintains isDone at false. When AsyncOperation.allowSceneActivation is set to true, isDone can complete. While isDone is false, the AsyncOperation queue is stalled.

So Unity intentionally doesn't let the load operation finish if allowSceneActivation is false. And when the queue stalls, the other load operations don't even start:

Unity does not call the second operation until the first AsyncOperation.allowSceneActivation is set to true.

An alternative solution for your scenario is to have a root GameObject in all of your scenes, and treat that root GameObject as the scene itself. That is: enable/disable the root GameObject of a scene to control whether that scene is currently active.

You can get the root GameObjects in a Scene with Scene.GetRootGameObjects.

\$\endgroup\$
2
  • \$\begingroup\$ Thank you! Do you think it is legitimate to use hacks like this? I am completely new to "scenes". Before I started dealing with multiple scenes, I thought that there was a well-defined scenario for situations like mine. The more I read in forums however and try myself and also read your answer, I am no longer sure. Can you tell me your opinion? Thank you very much! \$\endgroup\$
    – tmighty
    Commented Jul 29, 2021 at 5:24
  • \$\begingroup\$ @tmighty The only thing that matters is getting stuff done and shipping your game. Everything else is trivial. \$\endgroup\$ Commented Jul 29, 2021 at 8:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .