[85953-unity1.jpg*_|85953]
My Inspector
Undo.RecordObject works as intended and sets the object dirty when I make a change in my custom inspector, but this doesn’t seem to work for prefabs.
using UnityEngine;
using UnityEditor;
//Displays a custom editor for the CollisionDetection script
[CustomEditor(typeof(CollisionDetection))]
[CanEditMultipleObjects]
public class CollisionDetectionEditor : Editor
{
CollisionDetection scriptTarget;
private void OnEnable()
{
scriptTarget = target as CollisionDetection;
}
public override void OnInspectorGUI()
{
DrawDefaultInspector();
DrawTags();
}
//Draws the tags section
private void DrawTags()
{
//Title
GUILayout.Space(5);
GUILayout.Label("Tags this projectile will collide with", EditorStyles.boldLabel);
//Loops through all tags
for(int i = 0; i < scriptTarget.collidableTags.Count; i++)
{
GUILayout.BeginHorizontal();
EditorGUI.BeginChangeCheck();
//Editable text field
string tag = GUILayout.TextField(scriptTarget.collidableTags*.tag, GUILayout.MaxWidth(150), GUILayout.Width(150));*
-
//Boolean Field*
_ bool instantKill = GUILayout.Toggle(scriptTarget.collidableTags*.instantKill, “Instant Kill”);*_
* if (EditorGUI.EndChangeCheck())*
* {*
* Undo.RecordObject(target, “Changed Collision Tag”);*
_ scriptTarget.collidableTags*.tag = tag;
scriptTarget.collidableTags.instantKill = instantKill;
}*_
* //Remove button*
* if(GUILayout.Button(“Remove”))*
* {*
* scriptTarget.collidableTags.RemoveAt(i);*
* Undo.RecordObject(target, “Removed Collision Tag”);*
* }*
* GUILayout.EndHorizontal();*
* }*
* //Additional buttons*
* if(GUILayout.Button(“Add Tag”))*
* {*
* scriptTarget.collidableTags.Add(new CollisionTag(“New Tag”, false));*
* Undo.RecordObject(target, “Added Collision Tag”);*
* }*
* if(GUILayout.Button(“Clear Tags”))*
* {*
* scriptTarget.collidableTags.Clear();*
* Undo.RecordObject(target, “Cleared Collision Tags”);*
* }*
* }*
}
Inside the EndChangeCheck, it is correctly called when a change happens in the inspector, but not when a change happens on a prefab.
[85954-unity2.jpg|85954]
This new entry will disappear when I close and reopen my project
Does anyone know of an alternate way to set a prefab dirty, so that it correctly saves? Otherwise I have to set the values in Unity’s default list system, which completely negates all the hard work I’ve put into this inspector.
Thanks!
_*