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.

Question Get current state/graph name

Discussion in 'Visual Scripting' started by Maeslezo, Oct 10, 2022.

  1. Maeslezo

    Maeslezo

    Joined:
    Jun 16, 2015
    Posts:
    255
    Hello,

    Can I get the name of the running graph and/or state?

    Something like this:
    Get Name.png

    In this case the graph's name is "Dummy State".
    How can I get the name for using it in the graph?

    Thank you
     
  2. REDACT3D_

    REDACT3D_

    Joined:
    Nov 8, 2020
    Posts:
    222
  3. Maeslezo

    Maeslezo

    Joined:
    Jun 16, 2015
    Posts:
    255
    This gets the state machine name, but not the inner state where the subgraph is running. I mean the script state name
    2022-10-11_093142.png

    I'm getting "Scene Flow", but I need "Dummy State"
     
    Last edited: Oct 11, 2022
  4. REDACT3D_

    REDACT3D_

    Joined:
    Nov 8, 2020
    Posts:
    222
    Oh I see, you're looking to get the nested Subgraph from within the state graph.

    It does not appear to work like that with nested graphs that don't have an Object with the Graph Component but I could be wrong. may I ask why you're looking to reference just the string name of a nested subgraph?
    maybe there's another way to do the same final result you're looking for?

    are you just trying to send triggers?
     
  5. Maeslezo

    Maeslezo

    Joined:
    Jun 16, 2015
    Posts:
    255
    No big deal, no worries.

    I am doing a scene flow manager based on visual scripting.
    Each state is a scene, and you can go between scenes/states, loading and unloading the scene.
    Each state is the same, the only different is the target scene. So I was using a variable to define which is the loading scene. But the state name is actually the scene name, so I was playing around with the idea of getting the state name for using it as scene name.
    The visual scripting has toons of nodes, so it thought I couldn't find the correct node to get the state params (such as name, current status, etc).

    Anyway, it's more a curiosity than a necessity, I can use a graph variable, although I think such a node like I'm asking could be helpful, for debugging for example

    sceneflow.png

    state.png

    load scene.png
     
    REDACT3D_ likes this.
  6. REDACT3D_

    REDACT3D_

    Joined:
    Nov 8, 2020
    Posts:
    222
    Okay, you can just get the String Name of the Active Scene and have that transition to the correct node.



    This is how I would set it up.

    First, we make a Start State that every scene will start in. then send its transitions down to the corresponding Scene state with a Custom Trigger. We can't just start in Scene 1. We need to create the Enter State. Kind of like how the Animator Component starts off from a start state.
    States.PNG

    Any state toggled Green will be running or Active.
    Right click them and Select Toggle Start to make a State Active or not active.
    green bar.PNG


    Inside the starting Select Scene State, on Enter State we just Get the Active Scene and Get it's Name as a string and trigger a Custom Event.
    StateSelect.PNG



    Next, we need to configure the Transitions to accept the Custom Trigger Events to tell it to transition to the appropriate State.
    Transitions.PNG
     
    Last edited: Oct 14, 2022
  7. REDACT3D_

    REDACT3D_

    Joined:
    Nov 8, 2020
    Posts:
    222
    Inside one of the Transitions we can see the Custom Event Triggering the Transitions. it's like this in all 3 transitions but with the appropriate string as the input
    transitiontrigger.PNG


    Now inside each duplicate state is the code for the appropriate state. in this case we just print a message to console.
    We can also select the next scene with spacebar
    Scene State.PNG

    Here is what the console will print out
    console.PNG


    You'll also have to make sure all the scenes are in the Build Settings
    buid.PNG
     
    Maeslezo likes this.