HideFlags and Prefabs
My editor scripts create a prefab and then set it's hideFlags to HideFlags.NotEditable, HideFlags.HideInInspector and HideFlags.HideInHierarchy.
Everything goes right until I save and reload my scene. The prefab do not have the hideFlags any more.
This is a bug or i need to set every time the hideFlags?
Answer by Adam-Mechtley · Dec 01, 2016 at 07:51 AM
Hi @lassade! How are you setting the the hideFlags property? You need to make sure that it is properly dirtied and picked up as a change before you save the scene. One way is to do something like this:
 using UnityEngine;
 using UnityEditor;
 public static void SetHideFlags (GameObject prefabInstances[], HideFlags flags) {
     Undo.RecordObjects (prefabInstances, "Change Hide Flags");
     foreach (GameObject instance in prefabInstances)
         instance.hideFlags = flags;
 }
This is how I'm doing:
 [CustomEditor(typeof(Board))]
 public class BoardEditor : Editor
 {
     ...
     void OnSceneGUI()
     {
         ...
         instance = PrefabUtility.InstantiatePrefab(template) as GameObject;
         instance.transform.SetParent(target.transform, false);
         Undo.RecordObject(instance, "Change Hide Flags"); // i added this but no effect
         instance.hideFlags = HideFlags.NotEditable | HideFlags.HideInInspector | HideFlags.HideInHierarchy;
     }
 }
What if you also add a call to EditorUtility.SetDirty ()?
No luck with SetDirty.
I tried:
- Use SerializedObject to change m_ObjectHideFlags 
- Edit the scene file (yaml) and change m_ObjectHideFlags attribute 
- Also in the yaml I added a modification in the prefab's modification list to try change m_ObjectHideFlags 
Thx for the help
Your answer
 
 
             Follow this Question
Related Questions
HideFlags.HideInHierarchy not updating hierarchy in Edit-mode 3 Answers
Factories, serialization and the editor 0 Answers
Unity crashes whenever I try to modify a prefab 1 Answer
Dragging prefab onto object through code 1 Answer
Array does not serialize properly in a prefab instance for a scene 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                