Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by sheikh_Ati · Jul 27, 2017 at 01:15 PM · instantiateprefabparentdontdestroyonload

how do i make an instantiated object be a child of DontDestroyOnLoad object's child ?

i tried it and final after searching a loot i couldn't find any answer to it .. i have a game object that contains a canvas, in that canvas i have inventory and i am dynamically adding items in to it so when ever i dynamically add new item it wont get parented to the slots and if i make the canvas not a part of DontDestroyOnLoad object then it works fine. i don't know what i am doing wrong but please help.. !

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 Salanyel · Jul 27, 2017 at 02:58 PM 1
Share

Correct me if I'm wrong.

If you do not use "DontDestroyOnLoad", you can add a gameobject as a child of any element in your canvas.

But, if you canvas is in DontDestroyOnLoad", you can't ?

Am I right ?

avatar image sheikh_Ati Salanyel · Jul 28, 2017 at 10:18 AM 0
Share

salanyel yes that's exactly what i am trying to do here. i want my canvas to be persistent scene to scene an my inventory is happen to be a part of it. so that what happen when i instantiate an item it gets instantiated but in the scene only not in the dontdestroyonload.

2 Replies

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

Answer by sheikh_Ati · Jul 28, 2017 at 12:55 PM

i think it was Unity bug ... ! i just remove the instantiate(item) and rewrite it, play it and it works.

alt text


jvuy.png (17.1 kB)
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 Salanyel · Jul 28, 2017 at 02:48 PM 0
Share

If you rewrite your own code and that works, the problem is more in your own code ^^

Have a nice day !

avatar image
0

Answer by Salanyel · Jul 28, 2017 at 10:38 AM

Normally, if your canvas is part of the Dontdestroyonload, it will be not destructible.

If you are not sure about how you can access your game object, I recommend to use GameObjet.FindObjectWithTag("MyCanvasTag"); and a specific tag. Like this, you can access your canvas from every scene because the canvas is still a part of the scene.

You have to parent your item to your canvas too. Be sure you really place your inventory in the canvas. Maybe creating a panel to access it easily ? Depending on what you want.

The last thing you can do is to call the function DontDestoryOnLoad(MyInventory"); when you have instanciated your object.

Comment
Add comment · Show 3 · 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 sheikh_Ati · Jul 28, 2017 at 10:46 AM 0
Share

alt text here is the image of the hierarchy and the slot is where i want it to get instantiated and be achild of it i am using generic list to stor the game object in it and using that list element i ma trying to make that instentiated object a part of slots.

itemObj.transform.SetParent(slots[i].transform); itemObj.transform.position = slots[i].transform.position + new Vector3(24, -25, 0);

1df.png (16.1 kB)
avatar image Salanyel · Jul 28, 2017 at 11:35 AM 0
Share

Well, not a really generic method, but it seems it is working from the screenshot. Is it ?

avatar image sheikh_Ati Salanyel · Jul 28, 2017 at 11:56 AM 0
Share

nop ins$$anonymous$$d of instantiating i was trying to use a different approach but seems like its not working .. ! so i am back to where i was again. ! object gets instantiated but wont become a child of slot. alt text

asdasd.png (16.3 kB)

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

94 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can't Instantiate an object as child of another 1 Answer

My code is instantiating many prefabs, i only want one. 1 Answer

Generating prefabs at origin that are children of moving GameObjects? 2 Answers

How to spawn a prefab at a duplicate objects location 1 Answer

how do i instaniate prefab for once 0 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