• 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 /
This question was closed Aug 27, 2017 at 06:38 AM by vonSchlank for the following reason:

Other

avatar image
0
Question by vonSchlank · Aug 26, 2017 at 03:20 PM · localposition

Setting the localPosition of an Instantiated GameObject fails to move the object

Hi!

What's wrong with this really simple piece of code? Instead of setting the prefab's localPosition to 1000,1000, it just puts it to 0, 0. Debug says it's on 1000, 1000, yet, it is on 0, 0.

Either it is an Alien Mystery, or a well-sized facepalm.

Since i don't believe in Alien Misteries, but a have produced a decent amount of facepalms running my rounds around the sun, i'd vote for the facepalm...

Thanks in advance!

EDIT: AFAIK it worked before. A lots of times. Do i remember wrong? Any feedback would be appreciated...

EDIT 2: User error (AKA facepalm. As predicted :) ) I Instantiated a wrong prefab, with a script... yaaay...

 void DoItPlease(){
             Vector2 pos = new Vector2(1000f, 1000f);
             GameObject nextBase = Instantiate(basePrefab, new Vector2 (0,0), Quaternion.identity, gameObject.transform);
             nextBase.transform.localPosition = pos;
             Debug.Log("after: " + nextBase.transform.position);
         }
Comment
Add comment · Show 4
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 ivaylo5ev · Aug 26, 2017 at 03:41 PM 0
Share

Just out of curiosity, why do you log nextBase.transform.position ins$$anonymous$$d of nextBase.transform.localPosition. What are the values of both positions from the log?

Show more comments
avatar image hexagonius · Aug 26, 2017 at 05:35 PM 0
Share

Dead sure it's not a child of anything? If the log says 1000 1000 (position) but you see 0,0 (localPosition) that's an indication for a parent child relationship. Both can't be true.

Show more comments

1 Reply

  • Sort: 
avatar image
0

Answer by Bunny83 · Aug 26, 2017 at 07:09 PM

I suspect you set the scale of the parent to (0,0,0). That would collapse it's localspace to a single point. So no matter where you place a child, it will always appear at 0,0,0-

If that's not the case, you should post a screenshot of the parent object transform inspector and maybe one of the instantiated child.

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 vonSchlank · Aug 26, 2017 at 08:09 PM 0
Share

No, the parent is 1, 1, 1 Scale and (at this moment) there is only one instanced child. (Debug reads "position" (i need that later), not localPosition, but the parent is at Vector2 (0, 0) and it's scale is Vector2 (1, 1)) And Inspector shows that although i get "1000, 1000" from Debug, it is positioned on 0, 0. Uncanny...

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

70 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

Related Questions

Reference Error on localPosition variable 1 Answer

parent and .localposition? 2 Answers

Using custom physics engine - Is there a better way than setting localPosition 1 Answer

How use local position of prefab for my instantiate ? 1 Answer

Write IEnumerator for Movement 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