Search Unity

Object instantiate itself from memory

Discussion in 'Scripting' started by dreammaker9, Jul 4, 2019.

  1. dreammaker9

    dreammaker9

    Joined:
    May 21, 2018
    Posts:
    3
    Hi. I'm currently working on a project and I want an object to always be in every scene. I thought there was a way for a prefab to recognize that there are no instances of itself in the current active scenes and then instantiate itself in that scene, but I can't seem to find that anywhere. If anyone knows how to do this that would be great, thanks.
     
  2. ThermalFusion

    ThermalFusion

    Joined:
    May 1, 2011
    Posts:
    906
    There is nothing that can do this. Something can find duplicates of itself if properly managed. But nothing can know if itself doesn't exist, you need something else to manage this.
    There are various Unity Singleton implementation that gets rid of duplicates that should work well for your situation.
     
  3. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106