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 /
avatar image
0
Question by InteractivePie · Oct 05, 2015 at 11:59 AM · rigidbody2dprefabs

Why does Instantiate not reset childs positions in a prefab?

There is something I do not understand about the way how Instantiate works. I uploaded an example project to show the problem.

There is a prefab which exists out of these objects: Container (container holding 2 rigidbody2d child objects) -Rigidbody1(2D Cube rigidbody) -Rigidbody2(2D Cube rigidbody)

When I first run the game with the container object at 0,7,0 the cubes are childed at the same position. But when I instantiate the prefab during runtime say at position 0,7,0. Then the Container object indeed gets cloned to that position, however the child rigidbody objects gets the exact same position as the child objects from the object "container" who calls the instantiate. The container object has this code (the prefab variable has itself as prefab from the project hierarchy)

 using UnityEngine;
 using System.Collections;
 
 public class PlayerBehaviour : MonoBehaviour {
     public GameObject prefab;
     public static bool coolDown = false;
 
     IEnumerator CoolDown() {
         coolDown = true;
         yield return new WaitForSeconds (3);
         coolDown = false;
     }
     
     // Update is called once per frame
     void Update () {
         if (Input.GetKeyDown(KeyCode.Space) && !coolDown) {
             Instantiate(prefab, new Vector3(0,7,0), Quaternion.identity);
             StartCoroutine("CoolDown");
         }
     }
 }
 

How can I instantiate the prefab with child objects at the same position how i saved the prefab instead of the childs taking over the child position of the object who instantiates it? See example for what I mean.instantiate problem project In the example when pressing space the child objects takes over the exact position from the instantiate caller..

instantiateproblem.zip (467.5 kB)
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

1 Reply

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

Answer by InteractivePie · Oct 07, 2015 at 11:14 AM

For anyone who has the same problem: (found out the problem on my own)

It seems like if you have a prefab in your assets folder which has his own prefab as reference variable, Unity will change this into a self-reference instance variable. When you instantiate a self-reference it will also copy your positions inside the object (child objects etc.) So the workaround for me was to create another object that instantiates the prefab. This worked for me.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Rigidbody.addforce not working with prefab 1 Answer

Multiplayer different player prefab 0 Answers

PrefabUtility does not exist? 1 Answer

how can i make prefabs keep there inspector varibles 1 Answer

(Re-posted) How to save multiple of the same prefab clones 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