Incorrect Code

The code presented is not complete … should have just followed what was on the other fields to ensure the string value was saved back…

void StringToPrint()
{
    string currentStringToPrint = serializedObject.FindProperty("stringToPrint").stringValue;
    string requiredStringToPrint = EditorGUILayout.TextField("String to print", currentStringToPrint);

    if (currentStringToPrint != requiredStringToPrint)
    {
        serializedObject.FindProperty("stringToPrint").stringValue = requiredStringToPrint;
    }

}

I did it like this.

        var prop = serializedObject.FindProperty("stringToPrint");
        prop.stringValue = EditorGUILayout.TextField("String to Print", prop.stringValue);
        UnityEngine.Debug.Log(prop.stringValue);

i wonder if that last check in your code is doing something…

Privacy & Terms