Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 dannFlyJeRay · Sep 05, 2020 at 05:15 PM · transformtransform.positiontransform.rotationframe

Changes of Transform cancel on next frame after change

Hello everyone.

I started making game today, where transform.position and transform.rotation of different objects have to get back to their initial values in one point. It works correctly, but in the next frame after changing the transform it gets back to the value that was before the change.

I've tried a lot of options and disabled different functions to check if they are affecting that, but nothing helped.

Code:

GameController - he starts transform restart:

 public class GameController : MonoBehaviour {
     [SerializeField] private GameObject[] levelObjects;
     [SerializeField] private PlayerController player;
 
     public void ResetGame() {
         player.ResetTransform();
 
         foreach(GameObject obj in levelObjects) {
             if (obj.GetComponent<LevelObject_Parent>() != null) {
                 obj.GetComponent<LevelObject_Parent>().ResetTransform();
             }            
         }
     }
 }

Player Controller

     private CharacterController characterController;
     private Vector3 initialPosition;
     private Quaternion initialRotation;
 
     private void Awake() {
         characterController = GetComponent<CharacterController>();      
         initialPosition = gameObject.transform.position;
         initialRotation = gameObject.transform.rotation;
     }    
 
     public void ResetTransform() {
         gameObject.transform.position = initialPosition;
         gameObject.transform.rotation = initialRotation;        
     }
 

ResetTransform() on LevelObjects works correctly

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

Answer by dannFlyJeRay · Sep 05, 2020 at 05:39 PM

Found the problem.. and solution.

The problem is: CharacterController. It is used to move in FixedUpdate(), and changes the position of player to the one that was before.

Solution:

 private bool isMoveable = true;
 
     private void Awake() {
         characterController = GetComponent<CharacterController>();      
         initialPosition = gameObject.transform.position;
         initialRotation = gameObject.transform.rotation;
     }    
 
     public void ResetTransform() {
         isMoveable = false;
         gameObject.transform.position = initialPosition;
         gameObject.transform.rotation = initialRotation;        
         StartCoroutine(BecomeMoveable());
     }
 
     private IEnumerator BecomeMoveable(){
         yield return new WaitForSeconds(0.1f);
         isMoveable = true;
     }
 
     private void FixedUpdate() {
         if (isMoveable) Movement();
     }

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

176 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

Related Questions

Issues with copying Y axisrotation of another object 2 Answers

Possible way to improve performance moving large hierarchies? 1 Answer

How Do I Give Two Objects the Same Transform? 1 Answer

Coroutine - transform for every frame for duration? 0 Answers

any way to access the global position and rotation of a child object? 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