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
1
Question by diddykonga · Dec 20, 2013 at 05:12 AM · c#instantiateprefabplaymode

Clones are still in the hierarchy after exiting play mode

Is this intentional? If not, im Instantaiting a couple of 2D Toolkit Heart Sprites, and parenting them to the camera. For some reason when i exit out of play mode they dont get removed.

http://pastebin.com/Wa9PDgB5 Heres the code for the instantiating, any help is appreciated!

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by supernat · Dec 20, 2013 at 06:02 AM

No, it should not be doing that. Some plugins will do this by monitoring your hierarchy and re-creating the objects after you leave Play mode, but they are specifically designed to do this to save new objects created at runtime. Do you have any plugins that you are using?

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 diddykonga · Dec 20, 2013 at 02:04 PM 0
Share

I'm using 2D Toolkit and Unity Gems Finite State $$anonymous$$achine, I'm assu$$anonymous$$g it might have something to do with 2D Toolkit but I'm not sure.

avatar image
0

Answer by dkydev · Jul 25, 2018 at 06:11 PM

Old question but I just ran into this issue myself in 2018.1:

Seems like it is caused by setting the instantiated gameobject's parent transform directly - after instantiation. From your example:

 heart.transform.parent = camera.transform;

Instead use Object.Instantiate and specify the parent transform as the second parameter:

 GameObject heart = GameObject.Instantiate(healthSpritePrefab, camera.transform);
 heart.transform.position = position;

And the cloned gameobjects will be deleted when you exit playmode.

I haven't found any documentation yet as to why this is the case. If anyone knows please share. Thanks!

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 Mathyx92 · May 14, 2019 at 08:23 AM 0
Share

I encountered this issue too and used your solution but sadly it didn't work for me.

I instaniate an UI element and create it as a child of an existing UI element in the scene. Afterwards I instantiate more UI elements and set them as childrien from the first instantiated one. Neither the first form you show heart.transform.parent = camera.transform; or the second one ameObject heart = GameObject.Instantiate(healthSpritePrefab, camera.transform); works -.-

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

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to randomly instantiate other prefabs parallel? 1 Answer

Destorying prefab and instanstiating again? 0 Answers

Why is my Prefab Instantiating when the Scene is Loaded? 2 Answers

Accessing Script on instated prefab 1 Answer

(Unity 2D C#) Move instantiated prefab on Y axis? 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