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 ouoertheo · Apr 19, 2018 at 10:20 PM · instantiateprefabpositioningclone

Unable to set position of instantiated prefab

I have been combing the forums and debugging this for a while and am hoping someone here would kindly help me on this.

I have Unity 2017.3.0f3 and am trying to instantiate an object, then set its position. Here's the code snippet.

     if (dead)
     {
         rb2d.velocity = (new Vector2(0, 0));
         GameObject deathAnim = Instantiate(deathAnimation, new Vector3(3,3,0), transform.rotation);
         //deathAnim.transform.position = transform.position;
         Debug.Log(deathAnim.name + " " + deathAnim.transform.position + " " + transform.position);
         transform.position = startPosition;
         if (carrying)
         {
             DropObject();
         }
         dead = false;
     }

For some reason the clone always get's created at 0,0,0 and it won't move to the desired position I've tried:
GameObject deathAnim = Instantiate(deathAnimation, new Vector3(3,3,0), transform.rotation);

As well as

GameObject deathAnim = Instantiate(deathAnimation); deathAnim.transform.position = transform.position;

When I Debug.log the position of deathAnim, it has the correct position in the console. But when I pause the game and click on the deathAnim clone, the position in the inspector reads 0,0,0. This really confuses me.

Pleas help, this is going to give me an aneurysm. (sorry for my terrible suck with markdown).

alt text

2018-04-19-17-12-37-unity-201730f3-personal-64bit.png (71.0 kB)
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 JedBeryll · Apr 20, 2018 at 06:17 AM 0
Share

Isn't the AntDeatController script changing the position in awake or something? Or maybe setting it as a child of something?

avatar image Harinezumi JedBeryll · Apr 20, 2018 at 07:22 AM 0
Share

...or maybe it's the Animator that changes its position?
The positioning code is correct, so it must be something else changing the position.

1 Reply

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

Answer by ouoertheo · Apr 21, 2018 at 02:41 PM

You're right! The animator seems to be setting absolute values instead of relative. This was because I was not using Apply Root Motion and then Generate Root Motion Curves on the animation from my assets. Found out from this article https://answers.unity.com/questions/234957/animation-editor-relative-animation-positions.html

Thanks for pushing me in the right direction @Harinezumi

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

172 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 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

Simple Prefab Instantiate "(Clone)" Question 3 Answers

destroy asset is not permitted to avoid data loss? 0 Answers

I need help destroying a clone on function. 1 Answer

Saving Instantiated objects,Saving Instantiated objects 0 Answers

Prefab Enemy2 to track all prefab Enemy1's Instantiates transforms: How? 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