#SerialzedObjects
1 messages · Page 1 of 1 (latest)
It would be something like this
for(int i = 0; i < charactersProperty.arraySize; i++)
{
using (var charSO = new SerializedObject(charactersProperty.GetArrayElementAt(i).objectReferenceValue)
{
// draw the fields of the charSO that you want.
}
}
and "using" allows me to get each of the values individually
No using basically makes it so that the SerializedObject that you create will get properly cleaned up after you are done using it
okay that makes sense
so can i just access the character's parameters by using the member variables
Huh?
wait
sorry
i meant can i just access the member variables directly
and display them individually
charactersProperty.GetArrayElementAt(0).objectReferenceValue is the same as characters[0] basically
But then to access the properties of that UnityEngine.Object you need to make a SerializedObject for it
@green gulch
// Get the character property at index 0.
SerializedProperty characterArrayProp = charactersProperty.GetArrayElementAt(0);
// Create a SerializedObject for the value of the property we just got.
var charSO = new new SerializedObject(characterArrayProp.objectReferenceValue);
// Get the foo property from the character object.
SerializedProperty fooProp = charSO.FindProperty("foo");
// Set the value of the property.
fooProp.intValue = 42;
// Apply the changed value to the character.
charSO.ApplyModifiedProperties();
This is the equivalent
characters[0].foo = 42;
okay, i think i get it, i'll let you know if i have more questions
No
I can toggle my foldout but nothing is showing up. What do I need to change? https://pastebin.com/TXZPi7C6
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Are there any elements in the collection?
Also are there ay errors
Are you using C# properties and [SerializeField] with private fields, or public fields?
Oh I’m getting one error
It says on line 29 that object reference is not set to instance so I just forgot to name it
Oh wait
Not even that I don’t even have a name variable I just had a brain fart
Thanks, everything works now
I was wrong, some things still aren't working. Only the name gets displayed in the inspector, and only one of the characters will show up, not more than one. Also I can't actually update anything
here's what the script looks like now.
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Firstly you can use EditorGUILayout.PropertyField(..) which will help cutdown on the code
Also are you using C# properties and [SerializeField] with private fields, or public fields?
For example, what is Health?
public
So public int Health;?
yes
also what do i do this in place of
Any time you just want the default control/field for a property
like moveSpeed.floatValue = EditorGUILayout.FloatField("Move Speed", moveSpeed.floatValue);
Would just be EditorGUILayout.PropertyField(moveSpeed);