Search Issue Tracker

Fixed in 5.4.0

Votes

23

Found in

5.3.0f4

Issue ID

758692

Regression

No

Unloading a scene can destroy non-instantiated prefabs that are indirectly referred to by other currently-loaded scene

Assets Management

-

How to reproduce:
1. Open the attached project "UnloadSceneBug.zip"
2. Open and play Scene1
3. Left Mouse Click to the game view, it will load Scene2
4. LMC again and it will unload Scene1
5. Notice that message which was displayed by Scene1 disappears and the one in Scene2 is "success"

6. Build and run the project for standalone target
7. Repeat step 3 and 4
8. Notice that message which was displayed by Scene1 disappears and the one in Scene2 is "ndataRedirect was destroyed"

Note: By "indirect references" user means that an object in Scene2 contains a reference to a non-instantiated prefab X, and X in turn contains a reference to a non-instantiated prefab Y. After unloading Scene1, X remains valid, but Y disappears.

Comments (10)

  1. Denis159

    May 20, 2016 00:17

    have this problem Unity 5.4.0b17 (64-bit). I will download version 5.4.0b18
    I hope this is fixed

  2. greggaming

    Mar 24, 2016 18:49

    I can reproduce this bug in Unity 5.3.2p2

    My game's "loading" scene deletes itself half a second after the "main" scene loads. All "main" scene prefab references are available for that first half-second, and then turn null.

    Calling "DontDestroyOnLoad(prefab)" successfully stops my prefab references from turning null. It's a decent stop-gap, but not ideal.

  3. rempelj

    Feb 10, 2016 05:24

    Fixed for me in 5.4.0b5

  4. TapHazardGames

    Feb 08, 2016 04:30

    This issue is definitely still present, please re-open this.
    1 - Load base scene
    2 - Load scene B as additive
    3 - Second scene contains a resources.load call.
    4 - Unload scene B: Prefab is now missing from resources list and cannot be loaded until game is restarted completely

  5. dushanl

    Feb 02, 2016 23:02

    Note that I can still reproduce this bug in 5.4.0b4.

    Best workaround I could find is to immediately move any prefabs loaded with Resources.Load[Async] to a scene that never gets unloaded with SceneManager.MoveGameObjectToScene.

  6. Nicolas1212

    Jan 27, 2016 17:33

    This doesn't reproduce in the editor for me (5.3.0), but every time when building either on Android or desktop. Amazingly frustrating trying to find the cause of this. Building isn't exactly rapid

  7. maxxa05

    Jan 26, 2016 17:03

    It would help if at least calling Resources.Load wouldn't return null. It seems it doesn't even try to reload the asset if it was deleted.

  8. maxxa05

    Jan 26, 2016 16:24

    I meant: Ran in the same issue in 5.3.1p3 for our game Kôna.

  9. maxxa05

    Jan 26, 2016 16:23

    Ran in the same issue in 5.3.1p3 Kôna. We load/unload scenes for houses and such and use prefabs for terrain tiles. As you can expect, the terrain chunks get deleted, and we got big holes where we should have a terrain tile. So yes, that's a BIG issue.

  10. llutman

    Jan 21, 2016 21:50

    Ran into this problem today using 5.3.1f1.

    1) Load SceneA
    2) GameObject prefab = Resources.Load("MyPrefab", typeof(GameObject)) as GameObject;
    3) yield return SceneManager.LoadAsync("SceneB", LoadSceneMode.Additive);
    4) SceneManager.UnloadScene("SceneA");
    5) GameObject prefab = Resources.Load("MyPrefab", typeof(GameObject)) as GameObject;

    After (2), the prefab variable holds a valid reference.
    After (5), the prefab variable is null.

    It seems like calling UnloadScene somehow destroys the prefab, and it can't be loaded again. This only happens on a device, it works fine in the editor.

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.