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
0
Question by 1337GameDev · May 22, 2012 at 10:30 PM · instantiatetransformprefabpositionlocalposition

GameObject position and localPosition not changing in hiearchy, only in script.

I have a prefab i instantiate, and when i change its position and local position to 0,0 it doesn't seem to change in hierarchy view in editor. I have a debug system that prints out values to a gui text object and it says the local position before and after is 0,0. But in the editor it is a random huge value. Why would this be?

I'm using this code to change its positions:

     debugGText.permDebug("pos: (" + transform.position.x + "," + transform.position.y + ")");
     transform.position = Vector3.zero;
     debugGText.permDebug("pos(after): (" + transform.position.x + "," + transform.position.y + ") and localPos: (" + transform.localPosition.x + "," + transform.localPosition.y + ")");
     transform.localPosition.Set(0,0,0);
     debugGText.permDebug("localPos: (" + transform.localPosition.x + "," + transform.localPosition.y + ")");


This code works fine with no compile errors and print sout the location to the gui text object. Here is a screenshot of this in the editor window(I highlighted notable parts): There are no null reference exceptions and the script is on the gameobject i wnat to modify. Notice that the gameObjects's transform only has localPosition and not normal position. Why is this? It is not a child of another object....Just a prefab. Image screencap of editor

builderPosition.png (322.5 kB)
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 whydoidoit · May 22, 2012 at 11:14 PM 0
Share

$$anonymous$$y guess would be that something is changing it after your debug logging - where is that happening at the moment?

avatar image rutter · May 22, 2012 at 11:59 PM 0
Share

This script that's printing values, which object is it attached to?

  • The values you're printing refer to whatever object the script is attached to.

  • The values in the inspector refer to whatever object you have selected in the editor.

If those two aren't the same object, confusion might result.

avatar image 1337GameDev · May 22, 2012 at 11:59 PM 0
Share

Nope. I don't modify the position of the gameObject anywhere else.... Here is my scripts on justPaste.it.

http://justpaste.it/108g

avatar image whydoidoit · May 23, 2012 at 12:08 AM 0
Share

Hmmm, well your transform.localPosition.Set(0,0,0) probably isn't doing anything as transform.localPosition returns a copy of its position I believe. But clearly the position appears to be Vector3.zero in any case. Which makes sense as it has no parent right?

2 Replies

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

Answer by whydoidoit · May 23, 2012 at 12:12 AM

In you full script you have this code:

  private void updateTextPos()
     {
         Vector3 worldLocation = mainCam.ScreenToWorldPoint(buildGuiLocation);
         labelOfBuilder.transform.position = worldLocation;
     }

But labelOfBuilder is a component on the same game object as the Builder script, so it moves the builder to that location, hence your changed coordinates.

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 1337GameDev · May 23, 2012 at 12:16 AM 0
Share

Nice catch! how did i forget that?? I forgot to attach it to a child gameObject for this part of my implimentation.

avatar image whydoidoit · May 23, 2012 at 12:44 AM 0
Share

Just one of those - when you've exhausted the obvious and you don't know the code you see it with different eyes :)

avatar image paulaceccon · Mar 13, 2015 at 01:36 PM 0
Share

Hi, @whydoidoit. I'm struggling with a similar problem for months! Since you catch the problem here, would you $$anonymous$$d to take a look at my question? Thank you in advance.

avatar image
0

Answer by Giblon12 · Nov 26, 2020 at 11:40 AM

https://companynamegenerator.net

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 Giblon12 · Nov 26, 2020 at 11:41 AM 0
Share

https://companynamegenerator.net https://companynamegenerator.net/page/youtube-name-generator https://companynamegenerator.net/page/restaurant-name-generator-ideas https://companynamegenerator.net/page/podcast-name-generator https://companynamegenerator.net/page/event-festival-name-generator-ideas https://webdomaingenerator.com https://www.webdomaingenerator.com/page/youtube-name-generator https://www.webdomaingenerator.com/page/blog-name-generator https://webdomaingenerator.com/page/podcast-name-generator

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

7 People are following this question.

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

Related Questions

problem whit Instantiate Prefabs position. 0 Answers

How to follow multiple clones positions of an instantiate prefab having a velocity ? 1 Answer

Why can't I instantiate an object that is +5 in the x and z axis? 1 Answer

How to instantiate in self position. 1 Answer

Setting parent of instantiated object fails (Error: setting parent of prefab is disabled...) 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