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

(Case 951618) Physics: Raycast hits ghost collider

Discussion in '2017.2 Beta' started by Peter77, Sep 17, 2017.

  1. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,589
    Physics.Raycast hits colliders at their position from during scene activation, even when those non-static objects have been moved to another location.

    Please see the provided video, that shows how Physics.Raycast used to work in 2017.1 and how it does work in 2017.2.0b11.



    Reproduce
    1. Open user attached project in Unity 2017.1.1p2
    2. Open Assets/Scene.unity
    3. Press Play​
    Observe the line that represents the raycast and the red sphere that represents the hit point.

    4. Move 'Player' GameObject around​
    Observe the player capsule does not get hit if the raycast does not intersect it.

    5. Open project in Unity 2017.2.0b11
    6. Repeat from Step 2.​
    Observe the player capsule is hit even if the raycast does not intersect it.


    Expected
    'Ghosting colliders' should not be hit.
     
  2. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    Does the problem occur when moving with CharacterController.Move()?
     
  3. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,589
    Thanks for the idea, just tested it!

    It does occur when using CharacterController.Move() as well.
    It does not occur when I remove the CharacterController and add a CapsuleCollider instead and write to transform.position.

    I should also mention that I turned off the auto-sync features.
    Code (CSharp):
    1. Physics.autoSimulation = false;
    2. Physics.autoSyncTransforms = false;
    Turning on Physics.autoSimulation fixes the issue. But I wonder why does it work with a Collider in either mode, but not with a CharacterController.
     

    Attached Files:

    Last edited: Sep 19, 2017
  4. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    A character controller is raycast based so it would need the physics bodies to be refreshed before the raycast occurs, does that sound similar?
     
  5. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,589
    Here is the reply from QA:
    Many things for providing an explanation!
     
    PhilSA likes this.
  6. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Yep thought that would be the case. They should make sure that they update the physics viz if they aren't already, and draw colliders for things where they logically are rather than where the mesh appears to be.

    I'm sure they thought of that. Right? I hope. In any case someone should think about updating the physics vis or a lot more reports like this will be soaking up QA time.
     
    Peter77 likes this.
  7. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,589
    What I actually don't really understand is this:
    I have a hard time wrapping my head around this, because If I understand MelvMay's reply regarding autoSyncTransforms correctly, Unity does do a sync always, no matter whether autoSyncTransforms is set to true or false. The only difference seems to be when this happens.
    My thought is or was, because Unity does seem to sync transforms even with autoSyncTransforms set to false, the CharacterCollider changes on the transform should find their way over to the physics engine. But they don't seem to, which is why I submitted the bug-report. :confused:
     
  8. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Well that's 2D and this is Physx, so maybe it doesn't happen with Physx? @yant @MelvMay
    Would be nice to have some tips or ref I can advise or help forum users with :)
     
    Peter77 likes this.
  9. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    Here's my guess: the SyncTransforms that is always called once per fixed update even when autoSyncTransforms = false is actually called by the Physics.Simulate that is internally called when autoSimulation is true

    Edit: I'd be curious to see what happens if you set both autoSyncTransforms and autoSimulation to false but call Physics.SyncTransforms manually once per frame in your example project
     
    Last edited: Sep 20, 2017
    Peter77 likes this.
  10. yant

    yant

    Unity Technologies

    Joined:
    Jul 24, 2013
    Posts:
    595
    Hey. I commented the fogbugz case, but putting something similar here, for better transparency.

    So the CharacterController is actually two things in one internally, in PhysX. It's both a shape (ie Collider in Unity-speak) and a kinematic actor (ie Rigidbody with "isKinematic" set). Calling CharacterController::Move results in something similar to Rigidbody::MovePosition really, and the result of that is only available after a simulation was run. In this project, the simulation is never run (Physics.autoSimulation=false), and nothing is calling Physics.Simulate() either. That's why the CC's shape doesn't happen to be where you expect.
     
    hippocoder likes this.
  11. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,589
    Thanks for the reply.

    I wonder why does it work if I remove the CC and add a Capsule Collider then? In this case, it's still Physics.autoSimulation=false and Physics.Simulate() isn't called either, but the Capsule Collider position if where you'd expect it.
     
  12. yant

    yant

    Unity Technologies

    Joined:
    Jul 24, 2013
    Posts:
    595
    That's because a builtin-in collider doesn't include a hidden implicit kinematic actor, so its pose is reflected as soon it's been written to.
     
    hippocoder likes this.