- Home /
Custom Inspector: Using SeralizedProperty changes the prefab values!
I have a prefab which it is attached to the cube script. - CubePrefab - set damage = 5 in the inspector
I have another game-object Cube_Inventory, where I tried to display each Cube's Editor from the CubeList, on CubeInv's Inspector. Now here is the problem, when I changed the damage value to 100 on CubeInvetory's inspector, the cube's prefab also changed.
My goal for the cube inventory is to be able to view and modify the instances of cubes, but not to its prefab.
Please Help Thanks.
public class Cube : MonoBehaviour
{
public int damage;
}
public class CubeInventory : MonoBehaviour
{
public List<Cube> cubeList;
}
[CustomEditor(typeof(Skill_Cube))]
public class NewBehaviourScript : Editor
{
SerializedProperty CubeListProp;
void OnEnable()
{
CubeListProp = serializedObject.FindProperty("cube_List");
}
public override void OnInspectorGUI()
{
foreach(SerializedProperty curCube in CubeListProp)
{
Editor curCubeEditor = Editor.CreateEditor(curCube.objectReferenceValue);
curCubeEditor.DrawDefaultInspector();
}
}
}
line 11 is [CustomEditor(typeof(Cube))]. previous was a copy/paste error
Your answer
Follow this Question
Related Questions
How to change inspector with non-Monobehaviour objects ? 1 Answer
Insert new custom class element with _default_ values to a SerializedProperty array? 1 Answer
Initialising List array for use in a custom Editor 1 Answer
Unity Editor - Class variable value contrain 4 Answers
Access another objects property in an editor script 1 Answer