You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey, I was wondering if you could add in an overloaded method for the PooledEntity that takes in a boolean for whether or not the component being removed should be freed up in the pool. This might sound counter-intuitive considering that you want to free up components in a pool, but let me explain.
I have a finite state machine in my code, where each state has a list of components that describe that state. When states are changed, all the components in the old state are removed from the entity and all the components in the new state are added to the entity. However, when I remove the components from the old state, I do NOT want to free them up in the pool, because as long as the state machine is still active, the entity could switch back to that state and would require the components to be available only for the entity (and not freed up for use anywhere else).
Specific example: One component I have in my running state is a SpeedComponent set with a speed value of 8.0f. This component is stored in a list of components inside of my running state. The first time I enter the running state, everything works as expected. The player moves at the proper speed. However, once the player switches OUT of the running state, entity.remove(...) is called on the SpeedComponent, resetting its speed value to 0.0f which is the default value of the SpeedComponent. Now, this component is up for grabs in the PooledEngine ready to be used by any entity. This creates a problem because the component is not really up for grabs. It's technically still in use by the entity, even though it's not added to the entity.
In my case, all of the components get freed up when the state machine is reset, because once the state machine doesn't need to be used anymore, then it goes through all the states and all their components resetting them and putting them back in the pool.
TL;DR
Add in a boolean parameter freeUp in the PooledEntity's remove method that allows entities to remove components without resetting the component and putting it back in the pool.
The text was updated successfully, but these errors were encountered:
I faced same problem and the best solution I found so far (which work well) is to separate "definition" components from "state" components.
In your example, you would have a SpeedDefComponent containing speed (this component is never removed) and for instance a WalkingStateComponent containing nothing. Your state machine then add/remove WalkingStateComponent to reflect entity state. Your system process entities with both components.
Yeah, that's one solution, but it'll lead to a lot of duplicate components that aren't necessary. Already I'm up to around 40-50 components, and the last thing I want to do is split them apart into definition and state variants. Because I'm not in a hurry to get this fixed, I'd rather wait until the issue is addressed at the Engine level with my proposed solution.
Hey, I was wondering if you could add in an overloaded method for the PooledEntity that takes in a boolean for whether or not the component being removed should be freed up in the pool. This might sound counter-intuitive considering that you want to free up components in a pool, but let me explain.
I have a finite state machine in my code, where each state has a list of components that describe that state. When states are changed, all the components in the old state are removed from the entity and all the components in the new state are added to the entity. However, when I remove the components from the old state, I do NOT want to free them up in the pool, because as long as the state machine is still active, the entity could switch back to that state and would require the components to be available only for the entity (and not freed up for use anywhere else).
Specific example: One component I have in my
running
state is aSpeedComponent
set with a speed value of8.0f
. This component is stored in a list of components inside of myrunning
state. The first time I enter therunning
state, everything works as expected. The player moves at the proper speed. However, once the player switches OUT of therunning
state,entity.remove(...)
is called on theSpeedComponent
, resetting its speed value to0.0f
which is the default value of theSpeedComponent
. Now, this component is up for grabs in thePooledEngine
ready to be used by any entity. This creates a problem because the component is not really up for grabs. It's technically still in use by the entity, even though it's not added to the entity.In my case, all of the components get freed up when the state machine is reset, because once the state machine doesn't need to be used anymore, then it goes through all the states and all their components resetting them and putting them back in the pool.
TL;DR
Add in a boolean parameter
freeUp
in thePooledEntity
'sremove
method that allows entities to remove components without resetting the component and putting it back in the pool.The text was updated successfully, but these errors were encountered: