I was updating the Fleks Wiki to remove component hooks in place of the new lifecycle methods, when I realised the example in the Wiki was no longer possible 🗿.
val onAdd: ComponentHook<Box2dComponent> = { entity, b2dCmp ->
b2dCmp.body = inject<PhysicWorld>().createBody( /* body creation code omitted */)
b2dCmp.body.userData = entity // No longer possible, no entity reference from the component!
}
So instead we should pass the respective entity as a parameter to the component lifecycle methods.
override fun World.onAddComponent(entity: Entity) {
body = inject<PhysicWorld>().createBody( /* body creation code omitted */)
body.userData = entity // 🎉
}
Yeah it was my bad, I'm 100% certain the old tests for component hooks did have an assert for the expected entity but I removed it and never replaced it 😅.
I was updating the Fleks Wiki to remove component hooks in place of the new lifecycle methods, when I realised the example in the Wiki was no longer possible 🗿.
So instead we should pass the respective entity as a parameter to the component lifecycle methods.