i have a gui script and a go that both react to a touch event. I try to consume the gui event by returning true. When i print both events i see that the game objects events triggers earlier and the gui event does not consume it.
they are two separated game objects in the main collection. I try later to reproduce it with a new project. Thought there is a way to align the order which the objects are called
You have to make sure that the component that tried to consume the input acquired input focus after the other component. Maybe that could be the problem?
Yeah, ok, so it’s likely to happen, because most probably you also send the acquire input focus messages from all of them on init() - I guess, but the common reason is that all objects call acquire_input_focus() in init(), and the order of init() calls within the same collection is unspecified. Because of that, the final input order is not guaranteed to match the collection order - in Defold, input is not dispatched according to the order of game objects in the main collection/Outline. It is dispatched according to the input stack.
Details worth reading:
And return true only consumes input for listeners further down the input stack.
If you are sure that you want the GUI to be on top of the input stack, you should send the message to acquire input focus last - this is how stack works
So, to make sure the scripts acquire focus first, and gui script later, send the message in the GUI script as a response to another message.
I do something like this frequently:
From init() I send message postinit to myself: msg.post("#", "postinit")
In on_message() of the same script I handle this message, and in your case you can acquire the input focus here.
If you want the GUI to consume input before gameplay objects, make the GUI acquire input focus again when it is shown. Re-acquiring input focus moves that object back to the top of the stack. In practice, modal GUI should usually acquire focus when opened and release it when closed.
The Pause popup example in the manual does precisely this - acquire input focus when it is shown: Device input in Defold