Hello,
I’m executing a script on a game object and I’m trying to find a way of getting the object variables object ID via the script, so I can can access the object variables. I’m know how to access the variables by using an Object ID, but I don’t know how to get that id from the object by code.

My coding skills are at a beginner level so a detailed explanation would be great if anyone can help?

Thanks
  • Object variables are bound to an object via the ObjectVariablesComponent, which has the object ID stored in it's settings.

    Here's an example on how to get it from a game object (with complete namespace for the component):
    string objectID = gameObject.GetComponent<GamingIsLove.Makinom.Components.ObjectVariablesComponent>().settings.objectID;
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • Thanks Gil, that’s perfect
  • Hey Gil,
    This works great. How do i get/reference object variables from the game object the script is attached to it the variables are local and not set to an object ID?

    For example, I have a game object with an object variables component attached to it, the variables are set to local, and I want to access a string called ‘test’ ?

    Thanks
  • edited December 2023
    Get the variable handler from the component, or simply pass the game object or component to:
    VariableHandler handler = ComponentHelper.ToVariableHandler(yourThing);
    The handler gives you access to the variables.
    This also works for anything else with variables, e.g. a combatant, an ability, etc.
    Post edited by gamingislove on
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
Sign In or Register to comment.