Search Unity

scripts not found when entering a new scene

Discussion in '2D' started by rakso13, Feb 7, 2019.

  1. rakso13

    rakso13

    Joined:
    Jan 12, 2019
    Posts:
    2
    starting the game in a scene and everything works just fine. Then when i enter a new state scripts cant find other scripts when I use findObjectOfType and ends up being "null". Doesn't matter if I use Awake() or Start(). but if I instead initialize the variables in the update method everything works just fine again. My theory is that the game objects with the scripts haven't been loaded yet but this shouldn't be the case because unity themselfs states that it's safe to initialize a variable refering to another script during Awake because all the object should have been added in beforehand. Tell me if something is unclear.
     
  2. beanie4now

    beanie4now

    Joined:
    Apr 22, 2018
    Posts:
    311
    elaborate on this please "new state" and such?
     
  3. rakso13

    rakso13

    Joined:
    Jan 12, 2019
    Posts:
    2
    Sorry, meant Scene, always mix those 2 words up heh
     
  4. beanie4now

    beanie4now

    Joined:
    Apr 22, 2018
    Posts:
    311
    test each scene independently and make sure all of those objects exist, if all else fails remove findobjectoftype and replace with public variable and then drag the connection over