0
\$\begingroup\$

Let's say that I use a behaviour component that holds a function call to be called every update step assigned to an entity. Inside that function call I'm changing the active state for the entity to activated or deactivated, something like this:

void fun_update() {
 this_entity->set_active(true);
 if (this_entity->is_active()) { // This should return true or false?
  ....
 }
}

What would be more correct? To change the state for the current update iteration or wait for the end of the current update step to update the state of the entities?

I know that, unity3d for example, changes the current state, but when coding my own engine I find easier to update it at the end.

\$\endgroup\$
1
\$\begingroup\$

For me, set_active() having an immediate effect seems more usable because it does exactly what it says - the entity is active, and the next line of code can assume that.

I'm a little bit afraid of the word 'correct' up there, though, because it suggests that there is one "best way" to do things. If you aren't sure which is best for your code, then perhaps you can choose the one that seems most useful for right now. If that isn't clear, then try to write your entity and component code so both options are reasonable to implement. You can start to write some code that uses the system and see what feels best.

If you're very concerned about making the wrong choice and getting locked into an inconvenient structure, you could add both options - maybe set_active() and set_active_delayed() - and use the one that best fits each case.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.