Physics Engine Not Ready in Start or Awake

It seems that physics objects are not ready until one frame after Start is called.
Raycast will hit nothing in Start, but if I use a coroutine and yield one frame it hits.
This seems to likely be a bug or at least not the expected result.

Original Post on Discord

by user 553297758795333647

Hi, which call are you using for a raycast? For physics raycasts you need this.context.physics.engine.<method_name>

But you’re right - in awake the physics collider haven’t been created since this happens in onEnable (called immediately after awake) - in start everything should be ready tho

Ok you seem to be right - in start the physics step hasn’t been performed - we’ll fix this in the next update

Fixed locally so that start works - will be in the next release

Yeah. It was the physics.engine raycast.

by user 553297758795333647

Also I was wondering if you plan on adding boxcast, spherecast and other various shapecasting?
Right now I’m testing just using a box or sphere collider and translating from one point to another in a while loop and using the collider to detect all collisions. But I have a gut feeling this my have performance issues and is not the best way to do shapecasting.

by user 553297758795333647

Currently we have implemented sphereOverlap which might be useful already. Rapier (the physics engine that we’re using) does have other raycast methods and you could try using them directly until we have support in the engine: Scene queries | Rapier

Oh. How can I assess Rapier directly in code?

by user 553297758795333647

You can do this.context.physics.engine["world"] to get access to the rapier.world object

Thanks

by user 553297758795333647

How should I import Rapier into my script? Typescript doesn’t want to work without access to the shapes and functions it defines

by user 553297758795333647

here’s how we import it:
import { ActiveCollisionTypes, ActiveEvents, CoefficientCombineRule, Ball, Collider, ColliderDesc, EventQueue, JointData, QueryFilterFlags, RigidBody, RigidBodyType, ShapeColliderTOI, World, Ray } from '@dimforge/rapier3d-compat';

It might also be enough to import the types only in your case

If your code is inside an npmdef you might need to add rapier to that project as well:
"@dimforge/rapier3d-compat": "^0.9.0",

Okay. Thanks

by user 553297758795333647

Okay. So this works great. Now I’m trying to figure out how to map the physics collider to the gameobject its attached to.

by user 553297758795333647

This is the data the collider gets
image.png

by user 553297758795333647

I can’t seem to access the needle component I see here

by user 553297758795333647

Ah yeah true - we need to expose that. I’ll add it to the next release (probably tomorrow)

Okay cool. Thanks. It’s awesome to see fast iteration on this project.

by user 553297758795333647