Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

rigidbody initialization quick fix #10883

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export const ColliderComponent = defineComponent({
const hasCollider = useState(false)

useLayoutEffect(() => {
if (!rigidbodyComponent || !physicsWorld) return
if (!rigidbodyComponent?.initialized?.value || !physicsWorld) return

const colliderDesc = Physics.createColliderDesc(physicsWorld, entity, rigidbodyEntity)

Expand All @@ -102,7 +102,7 @@ export const ColliderComponent = defineComponent({
Physics.removeCollider(physicsWorld, entity)
hasCollider.set(false)
}
}, [physicsWorld, component.shape, rigidbodyEntity, !!rigidbodyComponent, transform.scale])
}, [physicsWorld, component.shape, !!rigidbodyComponent?.initialized?.value, transform.scale])

useLayoutEffect(() => {
if (!physicsWorld) return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ export const RigidBodyComponent = defineComponent({
canSleep: true,
gravityScale: 1,
// internal
/** @deprecated @todo make the physics api properly reactive to remove this property */
initialized: false,
previousPosition: proxifyVector3(this.previousPosition, entity),
previousRotation: proxifyQuaternion(this.previousRotation, entity),
position: proxifyVector3(this.position, entity),
Expand Down Expand Up @@ -118,8 +120,10 @@ export const RigidBodyComponent = defineComponent({
useEffect(() => {
if (!physicsWorld) return
Physics.createRigidBody(physicsWorld, entity)
component.initialized.set(true)
return () => {
Physics.removeRigidbody(physicsWorld, entity)
component.initialized.set(false)
}
}, [physicsWorld])

Expand Down
Loading