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.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Accessing a variable component from a monobahavior

Discussion in 'Visual Scripting' started by noahmizrahigala, Nov 11, 2021.

  1. noahmizrahigala

    noahmizrahigala

    Joined:
    Mar 8, 2021
    Posts:
    20
    I have a gameObject that has a "variables" component with several variables defined and a scriptMachine component that operates on those variables. I also have a monobehavior on the gameObject that needs to access the variables defines in the "variables" component.

    Is there a way to do this?

    Thank you.
     
  2. fabiareor

    fabiareor

    Joined:
    Jul 30, 2019
    Posts:
    5
    I ran into this same situation but I found out how to do it.
    Code (CSharp):
    1. using Unity.VisualScripting;
    2.  
    3. Variables.Object(gameObject).Get("variable name");
    You can use the Variables.Object(gameObject).Get("variable name"); in the update method to be constantly checking the value from that variable.