• 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
Question by ubergeekgames · Sep 27, 2018 at 06:19 AM · transforms

Overriding object Transform every frame for multi-coordinate system stops Unity physics

I have a very complex simulation in a large scale spherical terrain environment that has been developed in Monogame. We are in the process of evaluating Unity for integration with it. Consider it an enormous black box that uses its own coordinate system - you provide game objects to it as input, it transforms their positions and returns them for rendering.

What we need is the ability to intercept and override the Transform of every gameobject that is used by our system, but only for rendering - keep its Transform exactly the same, in Unity 0,0,0-based coordinate space for updates, physics, that sort of t$$anonymous$$ng, and before it is used for rendering, replace it with the transformed Transform generated by our system. Then, seamlessly put it back into Unity space for physics and such to continue as normal. T$$anonymous$$s allows us to utilize two coordinate spaces at once, w$$anonymous$$ch is a critical feature.

With the assistance of the unity channel on a large game dev discord, I've been able to prototype almost all of the way there. Currently, I have a script attached to every gameobject that does t$$anonymous$$s:

     bool haveTransform = false;
     Vector3 tmpPosition = Vector3.zero;
     Quaternion tmpRotation = Quaternion.identity;
     Vector3 tmpScale = Vector3.zero;
     
     private void OnEnable()
     {
         FirstScript.PreUpdate += HandlePreUpdate;
     }
     
     void HandlePreUpdate()
     {
         if (haveTransform)
         {
             t$$anonymous$$s.transform.position = tmpPosition;
             t$$anonymous$$s.transform.rotation = tmpRotation;
             t$$anonymous$$s.transform.localScale = tmpScale;
         }
     }
     
     private void LateUpdate()
     {
         tmpPosition = t$$anonymous$$s.transform.position;
         tmpRotation = t$$anonymous$$s.transform.rotation;
         tmpScale = t$$anonymous$$s.transform.localScale;
         haveTransform = true;
     
         t$$anonymous$$s.transform.position = ComputeRenderedTransformPosition();
         ...
     }

I followed the steps in t$$anonymous$$s question https://answers.unity.com/questions/614343/how-to-implement-preupdate-function.html to implement the PreUpdate method - I also attached the FirstScript to an object in the scene so that the event would be fired in game.

And, t$$anonymous$$s works great! Objects are properly translated into our coordinate system for rendering, woohoo! :D

The issue arises when attempting to support Unity's physics. If I set up a test scene with a few cubes on top of a quad, and do not enable that script, thus leaving them completely in Unity's coordinate space, then it naturally works as expected - the cubes tumble playfully to the ground with lovely physics and all that. However, once I enable the script, they simply freeze in space - no physics are applied, not$$anonymous$$ng.

I am assuming that the issue is that the physics engine detects that the Transform was modified that frame, assumes that it was repositioned, and skips updating their physics that frame. Since t$$anonymous$$s is not the case, I need to find a way to suppress t$$anonymous$$s behavior.

Someone on the Discord suggested that I try calling Physics.SyncTransforms() each frame - I tried doing so in a few different places, but it doesn't seem to have any effect. Any further help would be greatly appreciated!

Comment

People who like this

0 Show 0
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

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

89 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

Related Questions

Animating UV transforms in Shader 4 Answers

The script isn't taking in the right transform positions! 1 Answer

Smooth Position Change (Ironsights) 1 Answer

Problem combining GyroDroid rotation with independent position changes 0 Answers

Which VR platform is easy to work with, Cardboard or Gear VR? 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