InstanceIDtoObject namespace?

Hi

  1. Firstly I do not know why InstanceIDtoObject is in the editor namespace. I’m assuming its because its a very expensive operation. If somebody could explain that would be great.
  2. Is there a similar method outside of the editor namespace?
  3. If there is not a similar method. How can I get all instantiated objects. I will probably narrow it down by quering a certain gameobject but would like to know if I can get all objects… Actually that’s just stupid or is it not?

I notice you haven't marked any of the answers to your last several questions as "accepted". Go do that, and then I can help you with this.

so did it work? im sorry if im bad at solving errors....it sometimes take me multiple steps to fix a simple code and error

1 Answer

1
  1. The main reason is that the editor is where it’s useful. InstanceIDs allow editor code to associate objects at edit-time with objects at run-time, even as they are destroyed and recreated. There’s no corresponding need in the player.
  2. There’s nothing that specific. GameObject.Find, GameObject.FindWithTag, and Object.FindObjectOfType have related functionality. They’re all pretty slow, like InstanceIDtoObject is.
  3. Object.FindObjectsOfType(typeof(GameObject)) will do it, but again, it’s plenty slow.

There’s a lot of different ways to find objects. Other than the slow brittle last-resort ones I mentioned above, there’s having a reference to one (either set per-object or in the script’s import options) or having the object register itself during OnEnable. Which one’s the best is heavily dependent on your particular need… what are you trying to find, and what are your constraints?

unfortunately nope.... My friend came to me and helped me solved this issue... btw thanks for your help :D