Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 axis7818 · Aug 18, 2014 at 12:39 AM · errorprefab

prefabs and IDs

In my game, I have made a prefab of an enemy object and that prefab has a script attached to it that creates a sort of ID for each object so that when there are multiple in the scene, there is a way to distinguish between them. I then load the IDs and references to their game objects into a dictionary (c#) to organize the data. This worked fine for a little while.

However, when I quit unity and reloaded my project, I can't run the game without getting an error saying that there already exists an element with the same key in the dictionary. I am using the size of the dictionary as the ID for each element, so theoretically, with each element added, the size increases by 1 and thus, when the next ID is assigned, it will have a different ID.

What I find really weird is that when I delete all of those objects and then add them back with the prefab, it all runs perfectly until quitting and loading unity again. Hopefully this was enough information to answer the question and thank you for any answers!

Comment
Add comment · Show 1
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 IgnoranceIsBliss · Aug 18, 2014 at 12:46 AM 0
Share

I think we will need to see a little bit of code.

It also sounds like you may be best served using a list rather than a dictionary, since they won't throw the exception.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Cherno · Aug 18, 2014 at 01:35 AM

Do you actually save the data from your dictionary? Any data not serialized is lost when exiting play mode.

Comment
Add comment · 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

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.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

updateMassFromShapes error 2 Answers

Instantiating object from inventory 0 Answers

Problem Uploading Prefabs with Asset Store Tools 0 Answers

How can I make this GameObjects array remain permanent when i activate? 1 Answer

Distance betwen two objects.Error,bug,etc. 2 Answers


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