• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Blankzz · Aug 07, 2011 at 04:31 PM · objectinstancenamespaceid

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?

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image sneftel · Aug 07, 2011 at 06:47 PM 0
Share

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.

avatar image Blankzz · Aug 07, 2011 at 07:05 PM 1
Share

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.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by sneftel · Aug 07, 2011 at 07:43 PM

  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?

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Blankzz · Aug 07, 2011 at 08:39 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Getting instance ID from position 1 Answer

How to instantiate object onto other object from script 1 Answer

object not set to instance..........again. 2 Answers

Passing the object as event argument 1 Answer

Instantiate a COMPLETELY Unique Instance of an Object 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges