Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved SphereCastAll within a given PhysicsScene instance?

Discussion in 'Physics' started by adamgolden, Aug 23, 2020.

  1. adamgolden

    adamgolden

    Joined:
    Jun 17, 2019
    Posts:
    1,549
    In order to use physics while editing a prefab (unless I'm mistaken) you have to get the current PhysicsScene from the current scene. I use SceneView.lastActiveSceneView.camera.scene.GetPhysicsScene() to get it. Now this does work - physicsScene.Raycast is pretty much the same as Physics.Raycast.

    Until now I haven't needed SphereCastAll, but I decided this would be the best approach to try for something in particular. Why doesn't PhysicsScene have a SphereCastAll, when it does have a SphereCast? I mean in theory I could re-cast over and over, disabling colliders until there aren't any more and I have a list of them all, but I just get the feeling that if I'm even considering doing that, there must be something I don't know or haven't thought of?

    i.e.. Physics has SphereCast and SphereCastAll.
    https://docs.unity3d.com/ScriptReference/Physics.html

    ..but PhysicsScene only has SphereCast:
    https://docs.unity3d.com/ScriptReference/PhysicsScene.html

    Is there a way to either arbitrarily set the Physics Scene that Physics will use for subsequent calls, or otherwise use SphereCastAll within a given PhysicsScene instance? Thanks.
     
  2. adamgolden

    adamgolden

    Joined:
    Jun 17, 2019
    Posts:
    1,549
    Solved - you can pass RaycastHit[] to SphereCast from a Physics Scene instance. Hadn't noticed that.
     
  3. Rob3rT

    Rob3rT

    Joined:
    Dec 21, 2012
    Posts:
    1
    It's been a long time since you posted this, but can you please share how you solved this with an example code?