Are signals deterministic for single thread?

Godot Version

4.2.2-stable mono win64

Question

I am currently writing a program that’s organized roughly as follows

public Stack<Action> actions = [various actions]

public void ProcessActions() 
{
    while (actions.TryPop(out Action action))
    {
        action.Invoke();

        checkActionsHere(actions);
    }
}

When invoked, some of these actions cause signals to be emitted which in turn add actions to the actions stack. This leads to two questions.

First, say we have an action_A that emits signal B and then signal C which cause action_B and action_C to be pushed to the actions stack. Will these push actions occur before the checkActionsHere function?

Second, if that’s the case, will action_B be pushed before action_C?

I am unsure if having multiple threads would affect any of the answers to these questions the tree or how (if at all) the node tree structure might affect the ordering.

When signal is emitted all listeners callables get called immediately. In the same fashion as if you wrote the functions in place of the emit call. This is default behavior for signals. The order of callables is probably based on connection order, this is just a guess.

You have not provided enough information to say for sure. It depends on where the signal was emitted in the tree. If this script happens early in the process tree and the signals emitted later in the tree then no, the actions will be passed next frame. If vice versa then yes. If it’s a mix then no and yes?

1 Like

Thanks! So long as all listeners callables get called immediately, the ordering of those callables doesn’t really matter for what I’m doing.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.