Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Prefab unassigning after scenę restarts

Discussion in 'Prefabs' started by ZuriPL, Oct 15, 2019.

  1. ZuriPL

    ZuriPL

    Joined:
    Oct 4, 2019
    Posts:
    3
    I'm making a game and after trying to implement new mechanic, I'm occuring an error which unassigns at runtime a GameObject variable and when exiting play Mode everything works fine.

    Spawner script

    public GameObject obj;

    [...]

    void Update () {
    Instantiate (obj, Vector3. zero, Quaternion. Identity) ;
    }

    [... ]

    Player script; (prefab )

    [... ]

    void OnTrigerEnter2D (Colission colider) {
    Scene Manager. LoadScene(Scene Manager. GetActiveScene(). buildIndex) ;
    }

    If needed I will post a link to repo on GitHub, with whole project.