edited February 2023 in ORK Scripting
I have an ORKObjectVariables component to a gameObject. The same gameObject also have an Editor script attached to it. I want this editor script to change value of a variable contained in the ObjectVariablesComponent.

I manage to get a reference to the ObjectVariablesComponent and from this reference get the VariableHandler through GetHandler() function. From there I can do GetString("varKey") to get the actual value of the variable I want to edit (used Debug.Log() to make sure I get the proper variable).

Then I do Set("varKey", "varValue") to set the variable to another value. And it looks like it register properly in the component. I Debug.Log with GetString and the value of the variable has change as per the previous command. However the ORKObjectVariablesComponent Inspector does not refresh. It keeps the old value that was still stored in the variable.

Is there a way to Repaint the Editor of an ORKObjectVariables ?
Post edited by gamingislove on
  • Is this for changing it in-game or the settings in the editor?
    The code you posted is for changing in-game - the editor should refresh if you do some input, e.g. click on it.
    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!
  • edited February 2023
    It's not in-game, I'm trying to change the settings in the editor through a CustomEditor.

    Here's a snippet of code. The last debug displays the exact same thing that was typed in the EditorGuiLayout.Text box (which means the ObjectVariable register the information) but Unity's inspector does not update

    [CustomEditor(typeof(OrkGameObjectHandler))]
    public class OrkGameObjectHandlerEditor : Editor
    {
    private VariableHandler varHandler;

    public override void OnInspectorGUI()
    {
    varHandler = (target as OrkGameObjectHandler).GetComponent<ObjectVariablesComponent>().GetHandler();

    string newVarValue = varHandler.GetString("varName");

    newVarValue = EditorGUILayout.TextField("Variable Name", newVarValue);

    varHandler.Set("varName", newVarValue);

    Debug.Log(varHandler.GetString("varName"));
    }
    }

    public class OrkGameObjectHandler : MonoBehaviour { }
    Post edited by frednorm2000 on
  • The variable handler from the component is the in-game representation of the variables, not the settings.

    The variable settings can be accessed via the settings.initialVariables field of the component. However, this is a rather complicated set of classes and settings, so I'd recommend to first take a look at it.
    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!
  • Totally make sens. Thank you for your help. I'll have a look at it
Sign In or Register to comment.