Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question [SOLVED] Cant instantiate objects immediately after loading new scene

Discussion in 'Editor & General Support' started by lordumbilical, May 3, 2023.

  1. lordumbilical

    lordumbilical

    Joined:
    May 24, 2020
    Posts:
    38
    Objects I instantiate through script vanish immediately from the hierarchy if I instantiate them immediately after a scene load. If I wait a few frames, every thing works as expected, but if I run code that says "load scene, then instantiate the objects" then the objects appear and are somehow destroyed instantly. They flash up and disappear immediately, from the game view and hierarchy, as if they never existed. The same instantiation code works in all other situations, just not directly after a scene load. Would there be a reason for this? Is there a way to ready the scene so I don't have to force in a wait time to get around this?
     
  2. lordumbilical

    lordumbilical

    Joined:
    May 24, 2020
    Posts:
    38
    Scenes take time to load, so yes, I should be waiting before doing things, because even though my instantiations LOOK like they are happening in the new scene, they arent. So I added a scene loading check before continuing with activity. Problem solved.