Search Unity

Objects failing to populate variables when loading new scene

Discussion in 'Getting Started' started by Agrajags, May 5, 2021.

  1. Agrajags

    Agrajags

    Joined:
    Apr 15, 2021
    Posts:
    2
    Hi, I'm having problems with Unity loading new scenes. When I load the scene directly, the game runs fine. But when I load the scene from using SceneManager.LoadScene, the prefab objects that I instantiate have lost various variables, scripts, and components that are definitely on the prefab when looking at the cloned object's inspector. Here's a screen shot of the inspector unpopulated.
    upload_2021-5-4_19-49-31.png

    When looking at the prefab or when loading the scene directly, there are several variables populated and 2 bolt scripts.

    To make this even weirder, the object that it fails on is different each time I try. Here is one example of where it fails. You can see that it's trying to load a variable that hasn't been populated.
    upload_2021-5-4_19-53-44.png

    It seems that when changing scenes, the object isn't fully initializing before the code proceeds to the next block.

    Thanks for any advice you can give me or if you can point me in the right direction.