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 g0dafkq · Dec 10, 2020 at 01:11 PM · instantiateposition

Instantiated object coordinates from code aren't the same as the coordinates from Inspector?,Inspector Coordinates not the same as GameObject.Find Coordinates?

So I have this little code here:

     private static readonly int Rows = 10;
     private static readonly int Cols = 10;
 
 
     private readonly int[,] Matrix =
   {
     { 1, 0, 1, 1, 1, 1, 1, 1, 1, 1 },
     { 1, 0, 1, 1, 1, 1, 0, 1, 1, 1 },
     { 1, 0, 0, 1, 1, 1, 0, 0, 0, 1 },
     { 1, 1, 0, 0, 1, 1, 1, 0, 1, 1 },
     { 1, 1, 1, 0, 1, 0, 1, 0, 1, 1 },
     { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
     { 1, 0, 1, 1, 1, 1, 1, 0, 1, 1 },
     { 1, 0, 0, 1, 1, 1, 1, 0, 1, 1 },
     { 1, 1, 0, 0, 1, 1, 0, 0, 1, 1 },
     { 1, 1, 1, 0, 1, 1, 1, 1, 1, 1 }
     };
 
 
     public GameObject FloorTile;
     public GameObject Floor;
     void CreateFloor(int i, int j,int floor)
     {
         float size = FloorTile.transform.localScale.x;
         if (floor == 1)
         {
             GameObject FloorObject = Instantiate(FloorTile, new Vector3(i * size, 0, j * size), Quaternion.identity);
             FloorObject.name = "Tile[" + i + "][" + j + "]";
             FloorObject.transform.SetParent(Floor.transform);
         }
         if(floor==0)
         {
             GameObject FloorObjectPath = Instantiate(FloorTile, new Vector3(i * size, 0, j * size), Quaternion.identity);
             //Debug.Log(i+" "+j);
             FloorObjectPath.name = "TilePath[" + i + "][" + j + "]";
             FloorObjectPath.transform.SetParent(Floor.transform);
         }
         
       
     }
     void Start()
     {
         for (int i = 0; i < Rows; i++)
         {
             for (int j = 0; j < Cols; j++)
             {
                 CreateFloor(i, j,Matrix[i,j]);
             }
         }
 
         Debug.Log(GameObject.Find("Tile[2][4]").transform.position);
        
     }

I used Debug.Log(GameObject.Find("Tile[2][4]").transform.position); to see the position of my tile but when I check the console for the position of my Tile[2][4] it says 6.0,0.0,12.0 or something. When I look in the Inspector its -50.239422, 2.235324, -23,234342 (not exactly this, but you got the point).

Now my question is why are those coordinates different and how can I make them be equal?

Also I used "Instantiate to spawn another object near my "Floor" and its at the same spot as 1 tile of the Floor, but they have different coordinates in the Inspector... I'm totally confused.

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

Answer by sacredgeometry · Dec 10, 2020 at 07:34 PM

There are two sorts of coordinate space in unity (well three including screen space). World and local. One is relative to the world origin and the other is relative to your immediate parent (all the way up to world through your descendants)

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

200 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

FPS instantiate objects 1 Answer

Why are the children of the prefab I am instantiating getting the same exact transforms of its parent? 0 Answers

Instantiate a GameObject at the position of one of its child objects 1 Answer

Unity 2D - MoveTowards position not updating, not recgonizing new position 1 Answer

Instantiated Prefab wrong position 4 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