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 abeering · Jun 20, 2020 at 01:42 AM · positionrigidbody2dlocalposition

Single GameObject showing two different positions/localPositions

So I dug around quite a bit but I'm like .. really confused. I think this might have something to do with my rb2d configuration or something. But what I have is really simple:

I have NO idea how this one game object, depending on what script you are referencing it from can have two different positions and localPositions, but I haven't used unity in quite a while and I might be forgetting something really really simple here. I'm almost positive it's simple. But looking at the object hierarchy, the scripts, and I can't find any reason for this to be the case. The only reason I think it might have something to do with my rb2d is because in the game manager script, it's impossible for me to move the game object around with transform.position, it just always stays static from the time of game start. (It starts in the hierarchy, it's not instantiated later)


First I have a simple GameObject with a sprite renderer and a rb2d, and it has a script attached to it called Player.

 public class Player : MonoBehaviour
 {
     void OnMouseDown()
     {
       Debug.Log(transform.position);
       Debug.Log(transform.localPosition);
       Debug.Log(GetComponent<Rigidbody2D>().transform.position);
       Debug.Log(GetComponent<Rigidbody2D>().transform.localPosition);
     }
 }
 



I have a singleton game object which runs some level generation, very simple, which I've set the position of the the Player game object with, which also for the purposes of this test spams out its transform position and local position.

   public GameObject player;
 
 void Start(){
    // ...
     player.transform.position = new Vector3(-10, -10, 0f);
 }

   void Update(){
     Debug.Log(player.transform.position);
     Debug.Log(player.transform.localPosition);
   }



In this screenshot you can see the output of those Logs, as well as the position in the inspector of the player game object.

alt text


Here is screenshot of output from player script:

alt text


Here is Rb2d properties

alt text


Any help would be hugely appreciated thanks for taking the time to read this huge post.

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
1
Best Answer

Answer by luuhoang231 · Jun 20, 2020 at 02:03 AM

where are you get the ref player gameobject you should put it in awake method. If your gameManager is prefabs you cant put your gameObject in scene to

 public GameObject player;
  void Awake() {
  player = GameObject.Find("Player");
 }
  void Start(){
     // ...
      player.transform.position = new Vector3(-10, -10, 0f);
  }
    void Update(){
      Debug.Log(player.transform.position);
      Debug.Log(player.transform.localPosition);
    }




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 abeering · Jun 20, 2020 at 02:14 AM 0
Share

I see so I am referencing a prefab which is different than the instantiated object in the hierarchy.

Thank you so much!

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

157 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

Related Questions

Get instantiated prefab position from Collision Trigger 0 Answers

Camera rotation around player while following. 6 Answers

transform.position not moving object 2 Answers

C# can i set rigidbody2d to gravitate to point x but not y 0 Answers

Need insight on strange (simple) 2D object transform bug 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