[Simple question] Adding a new SerializedProperty to a SerializedObject
Hi!
I'm modifying a plugin I've bought, to better suit my game's needs. It uses CustomEditor for all the scripts, and I need to add a new variable to a script. I want to be able to change this variable from the editor, depending on the prefab, so I need to add this one as a new property.
I have added my new value to the current code, but it seems like I'm missing something. I have this code:
// [OLD - from the plugin] Finding serialized properties...
oldPluginProperty1 = serializedObject.FindProperty("oldPluginPropertyNumberOne");
oldPluginProperty2 = serializedObject.FindProperty("oldPluginPropertyNumberTwo");
...
// MY NEW CODE:
myNewProperty = serializedObject.FindProperty("myNewProperty");
... myNewProperty returns a null value! Obviously I need to declare "myNewProperty" somewhere and add it to serializedObject, but I've scoured through the entire plugin and I cannot find where they are added. I've never done this before and everybody seems to have it so figured out that nobody talks about it in any thread! NOT EVEN IN THE UNITY DOCS!
How do I add myNewProperty to serializedObject so that FindProperty() doesn't return null? Is it somewhere within the actual editor? Should I do it by code?
Thanks in advance!
Answer by Trickman · Jan 22, 2018 at 04:29 PM
OH BOY AIN'T I A DUMBASS. You need to have "myNewProperty" declared as a regular variable, too, not just as a serializable property, and it should have the same name as you indicated in the string parameter from "FindProperty()". Sorry for that.
Your answer
Follow this Question
Related Questions
Custom Editors - Array of Custom Classes 2 Answers
How to iterate over Serialized List? 1 Answer
EditorGUILayout.EnumPopup shows always the same selected option but works as programmed 1 Answer
Editor Int sliders affecting each other 0 Answers
i want to make notification when push build button 0 Answers