Closed zaknafean closed 5 days ago
Hm may well be my implementation. When I add an await process frame this goes away.
for stm_instance in get_tree().get_nodes_in_group('smashable'):
if stm_instance.owner == self:
stm_instance.smash_the_mesh()
var explode_callback = func(rb: RigidBody3D, _from):
rb.apply_impulse(-rb.global_position.normalized() * Vector3(1, -1, 1) * 5.0)
await get_tree().process_frame
stm_instance.chunks_iterate(explode_callback)
So i may just be trying to apply the physics too soon. You can probably consider this closed, but a note on this may be useful in the docs, since the error one gets is worse than the actual situation.
I'm glad to hear you managed to solve the issue!
You're correct that the error likely stems from trying to apply physics to a RigidBody3D
before it's fully initialized in the scene tree.
Awaiting a process frame resolves this because, by then, the object is properly registered in the physics space.
Another approach you could try in cases like this is using the call_deferred
method.
For example:
stm_instance.chunks_iterate.call_deferred(explode_callback)
This ensures that the callback is executed after the current frame completes, which should help ensure that the object is fully ready.
I'll make sure to add a note in the documentation to help others avoid this issue in the future.
Getting this error when I try to do the explode_callback.
So was wondering if there was a mistake I had made in set up or not. The code I called it from was in my enemies death method, and looked something like this:
As the enemies are currently made of multiple meshes.