- Home /
InstanceIDtoObject namespace?
Hi
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.
Is there a similar method outside of the editor namespace?
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.
Thanks for pointing that out to me. I don't want to appear rude to people who have kindly helped me. Anyway all done now.
Answer by sneftel · Aug 07, 2011 at 07:43 PM
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.
There's nothing that specific. GameObject.Find, GameObject.FindWithTag, and Object.FindObjectOfType have related functionality. They're all pretty slow, like InstanceIDtoObject is.
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?
Thanks for the info. I have a couple of uses for it. The main one is for a replay system where the objects and their actions/operations are loaded and parsed and applied to the object. I'm trying to do some planning and find some possible solutions. I may need to reference Objects by ID because I want to be able to stream the replays. I'm going to try and implement it so the operations are performed whilst the replay file is parsing and compare performance and loading times with other solutions. Hope that makes sense.
I'll use Object.FindObjectsOfType(typeof(GameObject) and then find the one with the correct id. I thought maybe the objects get stored in order of id so a method would have provided faster searching.
Your answer
Follow this Question
Related Questions
Object reference not set to an instance of an object 0 Answers
Why does this cause an "object reference not set to an instance of an object?" 2 Answers
NullReference Exception when adding a class 2 Answers
Pause menu error NullReferenceException:Object reference not set to an instance of an Object .js 1 Answer
Object reference not set to an instance of an object. 0 Answers