Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

4 seconds to set transform.position???

Discussion in '5.6 Beta' started by sgower, Mar 23, 2017.

  1. sgower

    sgower

    Joined:
    Mar 9, 2015
    Posts:
    316
    I noticed a strange 4-20 second delay happening in my game and I narrowed it down to the following
    2 lines of code that set the transform.position of a gameObject. In my last profile capture, each of these took 2 seconds, but it had taken even longer in previous tests.

    Code (CSharp):
    1.     Profiler.BeginSample("updateJointPositionfffffffff666");
    2.                 this.gameObject.transform.position = attachedWand.transform.position;
    3.                 Profiler.EndSample();
    4.                 Profiler.BeginSample("updateJointPositionfffffffff777");
    5.                 this.gameObject.transform.position = this.gameObject.transform.position + posDelta;
    6.                 Profiler.EndSample();
    I eliminated the problem by changing the above to:

    Code (CSharp):
    1.   // Profiler.BeginSample("updateJointPositionfffffffff666");
    2.               //  this.gameObject.transform.position = attachedWand.transform.position;
    3.                // Profiler.EndSample();
    4.                 Profiler.BeginSample("updateJointPositionfffffffff777");
    5.                 this.gameObject.transform.position = attachedWand.transform.position + posDelta;
    6.                 Profiler.EndSample();
    Does anyone know what could explain this? Obviously the first set of code was setting the transform position twice when only once was necessary, but why would the first code cause a massive profile spike?
    Note the object in question is an object, with a few child objects, and those child objects have hundreds of colliders. I'm sure it's related to these colliders, but still seems like a mystery.

    I'm using 5.6f11 btw.
     
  2. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,664
    Sounds like there is more going on here than just the two settings occuring... are these in an update/fixedupdate loop? If so, does posDelta change? Does attachedWand move?
     
  3. sgower

    sgower

    Joined:
    Mar 9, 2015
    Posts:
    316
    Yes, these are called when the Vive controller trigger is clicked. And yes attachedWand does move (it's the Vive controller).
     
  4. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,664
    Oh okay, so this a VR project then. Well, perhaps if there really is something strange going on that isn't caused by your own code, somebody else will have ran into it as well, and have an answer for you. Sorry but I haven't had a chance to get into VR dev much yet, so I can't be of much assistance!
     
  5. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    3,132
    Hi Spanky11,
    Could you please file a bug report with a minimal reproduction case for this issue?
     
  6. sgower

    sgower

    Joined:
    Mar 9, 2015
    Posts:
    316
    Sorry, this isn't one that I can create a reproduction case for. I think it's an extreme edge case, and my project is far too large to send. thanks, though. I did find a workaround, so (even for me) it's a low priority. Really I was wondering if anyone had an idea about what might cause this issue.
     
  7. Gizmoi

    Gizmoi

    Joined:
    Jan 9, 2013
    Posts:
    327
    You mention that the object has children with lots of Colliders. This suggests to me that they are marked as static or do not have RigidBody components attached. This means that PhysX will recalculate all these colliders when they are moved.
    If you look in the Profiler it should show up as StaticCollide.Move (Expensive delayed cost) or something similar.

    If I remember correctly Unity were talking about removing the restriction on this if there is no RigidBody attached but it is also not marked as static. I've always just added a Kinematic RigidBody to every Collider that isn't static that might move at some point anyway to make doubly sure.

    TL;DR Add a RigidBody to each GameObject that has a Collider on it that moves.
     
    Cromfeli likes this.
  8. sgower

    sgower

    Joined:
    Mar 9, 2015
    Posts:
    316
    thanks, will check this. Regarding adding RigidBodies, isn't it the case that when you have a parent object with children, and you set the parent to non-kinematic, that you should remove the Rigidbodies from the child objects? My understanding is that when you do this, the parent Rigidbody takes over and all the sub-colliders are handled by it.
     
  9. Gizmoi

    Gizmoi

    Joined:
    Jan 9, 2013
    Posts:
    327
    That is correct, but from what I understand, moving the child colliders within the RigidBody will cause the same re-calculation to occur. So you can group up your colliders under a parent RigidBody, as long as you don't then move the children independently from the parent.
     
    sgower likes this.