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
1
Question by Fifax · Sep 03, 2019 at 11:24 AM · positiontransform.positionpositioningreset-position

How to get all child objects back to its start position.

Hi everyone!

I am developing AR app using Unity 2019.1.0f.2 and Vuforia SDK and I came across annoying problem.

I need to reset position of my main object (model of an camera) to its starting position. So I wrote simple functions to do that:

PositionReset.cs

 private static PositionReset instance;
 
     public static PositionReset Instance
     {
         get { return instance ?? (instance = GameObject.FindObjectOfType(typeof(PositionReset)) as PositionReset); }
         
     }
 
     /// <summary>
     /// main 3D object instance
     /// </summary>
     public GameObject mainObject;
 
     /// <summary>
     /// hold original position of all objects
     /// </summary>
     private Dictionary<string,Vector3> startPosition = new Dictionary<string, Vector3>();
 
 
     public void Awake()
     {
         if (instance == null)
             instance = this;
     }
 
     // Start is called before the first frame update
     void Start()
     {
 
     }
 
     // Update is called once per frame
     void Update()
     {
         
     }
 
     public void ResetPosition()
     {
         mainObject = GameObject.Find("193.0-0 Ognioszczelna Kamera Cyfrowa typu OKA-1_C 1");
 
         foreach (Transform transform in mainObject.GetComponentsInChildren<Transform>())
         {
 
             Vector3 localPosition;
             if (startPosition.TryGetValue(transform.name, out localPosition))
             {
                 Debug.Log("RESET: Name: " + transform.name + " Local position: " + localPosition);
 
                 transform.position = localPosition;
                 //transform.position.Set(localPosition.x,localPosition.y,localPosition.z);
             }
 
         }
 }
 
 
 public void GetStartPosition()
     {
         //startPosition 
 
         //Transform[] childTransform = GetComponentsInChildren<Transform>();
         mainObject = GameObject.Find("193.0-0 Ognioszczelna Kamera Cyfrowa typu OKA-1_C 1");
 
         if (startPosition.Count < 1)
         {
             foreach (Transform transform in mainObject.GetComponentsInChildren<Transform>())
             {
                 Debug.Log("ADD, Name: " + transform.name + " Local position: " + transform.localPosition);
                 startPosition.Add(transform.name, transform.position);
 
 
             }
         }
 }

I use function GetStartPosition() on imagetarget detection in another class, and then with button click from UI want to reset position with function ResetPosition(). What I get in the end is that all objects end up in random places. What am I missing? How does Unity take the position of those objects? in my opinion they should come back to starting point that I grabbed with GetStartPosition().

Here are some screenshots from scene view. Starting point(which should be end point) and actual messed result. alt text alt text

I would appreciate any help. Thanks, Simon

cam.png (134.8 kB)
cam1.png (138.1 kB)
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 brarife · Sep 03, 2019 at 03:03 PM

Add the coradnites of its stars pos to the script for reset

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

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

Related Questions

Are I stupid? Vector3 1 Answer

OnTriggerEnter and position problem 0 Answers

When walking animation loops in timeline, it resets the player´s position back to the start 0 Answers

instantiated gameobject position is not working 0 Answers

I'm making a small VR game for school and i need a VR sword slash but not sure how to compare the Pos better. 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