State Machine: counting states/state changes

Godot Version



Hey guys. Coming back with another question. I have couple instances in the scene of the same node representing mushrooms with two states {SMALL, GROWN}, player can water them which triggers growing. I want something to happen when all instances have grown. How should I count them?

The simplest solution is probably to add your mushroom scene to a group, then at runtime regularly loop over all nodes from that group and check their respective state. If you finish looping over all mushrooms without finding one that is still in the SMALL state, all instances have grown.

A slightly more involved (but also more performant) approach would be to have the instances emit a signal once their state changes, and keep track of the number of created instances which are still in the SMALL state in the parent node.

1 Like