Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

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:
    14
    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:
    1,045
    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:
    14
    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:
    1,045
    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:
    14
    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:
    1,045
    Sound decision.