Zay-ES GroundCheck Component

Hello. Another one of my silly questions…

So I need to be able to tell whether or not an Entity is on another RigidBody. This is only for Entities in the PhysicsAppState.

To do this I’ve created a GroundCheckComponent simply hold a Boolean. This component is updated in the PhysicsAppState regularly. So now I can check whether or not a component is “grounded” by checking this component.

My question: Is this proper usage of ECS?

Sure. Though ultimately it depends on what you are using this information for.

I’m using it in AppStates that require the entity to be on the ground. For example, in my CharacterActionAppState: the player should only be able to jump if he is grounded. However, to do this I need access to the PhysicsState to ray test. So it seems proper to add a component that the PhysicsState handles.

Also on A side note. Is it okay to just re-set the same component(versus creating a new one, like in the examples) to trigger a “change” in an entity

But if it isn’t changed then why trigger a change? There is something about the question I don’t understand.

Well it is changed. As in the PositionComponent. I just update and entity.set(samePositionComponent). instead of creating a new PositionComponnet with the updated data.

The problem with that is that you are changing the state of views when they don’t expect it.

Why not just set a new component?

Just felt weird making new ones. Felt pointless. But now it hit me. Setting the same ones would make entitySets miss important changes right?

It might. But what it definitely does is change the ‘view’ an EntitySet has without it every calling applyChanges().

Normally, Zay-ES is 100% thread safe. When you start modifying components directly then you destroy that or you have to handle multithreading in your component yourself. It’s just not worth it.

Make your components immutable unless there is really good reason not to. “It feels wrong” is not really a good reason.

Yeah. I’m understanding all of this now. I was just being nice to GC.

It’s a false optimization because all of the stuff going on under the covers is already making temporary garbage. Unless you are on Android then the generational GC makes these short-lived objects nearly free to GC. (And I guess Android is getting better.)