Search Unity

Exposing state's state to transition

Discussion in 'Visual Scripting' started by cviot_acreos, Aug 8, 2022.

  1. cviot_acreos

    cviot_acreos

    Joined:
    Sep 6, 2021
    Posts:
    15
    Hi,

    I am playing with visual scripting and I have difficulties understanding how state and transition should world. together. I would like to share some variable between a state and each possible transition to avoid duplication. Basically, I want the state to do its logic in its OnUpdate Method and updates its "internal state" (ie own variables). Then, it should give "a view" in it internal state to its connected transitions that can decide by themselves if it needed to transit or not. Is is possible to do that? I think I can use object variables (or even bigger scope ones) but I don't want to do that as all my states and transition would have access to it.

    Basically, I want to share a variable only for the node in the red rectangle in the graph below:

    upload_2022-8-8_19-16-23.png
     
  2. PanthenEye

    PanthenEye

    Joined:
    Oct 14, 2013
    Posts:
    2,077
    You can use a custom event with an argument to communicate between a state and its transition. The event can pass N amount of arguments.
     
  3. cviot_acreos

    cviot_acreos

    Joined:
    Sep 6, 2021
    Posts:
    15
    Sweet. Does every transition in every graph will receive the event? In that case I probably need to use one of the argument to avoid that?
     
  4. PanthenEye

    PanthenEye

    Joined:
    Oct 14, 2013
    Posts:
    2,077
    Custom events connect via matching string name and the same GameObject reference. You can use differently named custom events for different transitions.
     
  5. cviot_acreos

    cviot_acreos

    Joined:
    Sep 6, 2021
    Posts:
    15
    While it can work, I am not sure this will scale very well. This will result in a lot of hardcoded string in every graph that can't even be refactored easily. I think I will pass on Bolt for now and wait for it to mature before adopting it.
     
    PanthenEye likes this.
  6. PanthenEye

    PanthenEye

    Joined:
    Oct 14, 2013
    Posts:
    2,077
    Sound decision.