Search Unity

Global Custom Event - Bolt

Discussion in 'Visual Scripting' started by danUnity, Nov 15, 2020.

  1. danUnity

    danUnity

    Joined:
    Apr 28, 2015
    Posts:
    229
    Hi,

    When using Bolt, I encapsulate every element/concept into a super unit with inputs and outputs. Some of those outputs are Custom Events that I trigger from my scripts. Lastly, many of those encapsulated elements are Singletons so there's only one in the scene which makes them global the scene.

    Everything works fine until I use State Machines.

    Custom events seem to be only triggered in the current state.

    Sometimes, I trigger things in a transition and I want to capture the custom event in the state I'm going to but currently, that custom event won't ever be fired in the state I'm going to.

    Sure, you could check on Enter State but it goes against the encapsulation logic.

    Is there any way to have an option to make those Custom Event global?

    Thanks
     
  2. Ex-Crow

    Ex-Crow

    Joined:
    Aug 14, 2020
    Posts:
    111
    I believe it's not the issue with events, but how the state machine is working in general. Only one state and its outgoing connections can be active at a time. So if you want to fire something from one state to another state and they're directly connected - it just won't happen with any kind of event. You could, however, try out creating a superstate (a nested state machine). An event fired from a parent state should be receivable by currently active child states and their outgoing transitions.

    Or have transitions receive active state events before transitioning to the next state.

    Another way would be to implement two parallel state machines. Bolt can have any number of Start states in the same graph, which means you can have many separate or connected state machines that can transition in parallel. Since both state machines have an active state, you should be able to fire events between them.

    But it sounds like a state machine might not be the right solution in this case. If two directly connected states share their state, it's not a finite state machine anymore.
     
    Last edited: Nov 15, 2020