Reputation: 39
My script extracts all child objects from a parent object. I need to assign materials individually to child objects or material to all objects via parent object.
Currently when I change a child material, all other child object materials get changed aswell.
How it looks in Unity when I change a child material
Here is my code
if (includeChildObj == true)
{
EditorGUILayout.Foldout(includeChildObj, "List of Child Objects", includeChildObj);
for (int i = 0; i < Geometry.getChildNames().Count; i++) // loop through all child objects
{
GUILayout.BeginHorizontal();
GUILayout.Label(Geometry.getChildNames()[i]); // display object name
EditorGUILayout.PropertyField(serializedObject.FindProperty("SelectMaterial")); // find an enum which allows the dropdown list
GUILayout.EndHorizontal();
serializedObject.ApplyModifiedProperties();
}
}
How is see it is that inside the FOR loop, for every Geometry object, I need to instantiate a new object of the corresponding enum. I am not sure how to do this as I am using CustomEditor not Monobehaviour.
Thank you!
Upvotes: 0
Views: 81
Reputation: 47
It appears that you are referencing the same serialized object in each iteration of your for loop. So there's only one value being read and assigned to in each iteration, which explains the behaviour you're seeing. It's not clear to me what your requirements are, but perhaps you need multiple instances of that serialized object, one per Geometry child?
Upvotes: 1