Hello,
I am currently struggling to find a solution to this problem: basically, on Unity 2017.2.1f1, I am getting this error:
An asset is marked with HideFlags.DontSave but is included in the build:
Asset: 'Library/unity editor resources'
Asset name: sv_label_1
(You are probably referencing internal Unity data in your build.)
UnityEditor.BuildPlayerWindow:BuildPlayerAndRun()
I tried going through all the code I have, trying to find incorrectly referenced Editor code.
Can anyone help me pointing me more precisely?
Thanks!
↧
Error preventing build "An asset is marked with HideFlags.DontSave but is included in the build"
↧
Can I serialize data in an Editor class?
I have a custom inspector for a MonoBehaviour. The target is a singleton, and there is only one in a scene at any time. I'd like to preserve, among other things, the state of the editor foldout booleans when changing inspector target (selecting different objects) and (de)serializing the scene. The way I currently achieve it is by having the foldout booleans stored in the editor target, and while it works, the editor state doesn't really belong there.
I haven't succeeded in storing them in the editor object itself. It seems that it may be recreated each time you start inspecting the target, and it doesn't live in the scene hierarchy so it's not serialized. (I've tried the `System.Serializable` and `SerializeField` attributes, different `HideFlags` and setting the editor object dirty, to no avail.) The `Editor` class derives from `ScriptableObject` but where does it live? Can I force it to persist in the scene? Or create and use a scene object (like a MonoBehaviour) with certain `HideFlags` without leaking stuff? Is there some API like `EditorPrefs` but per-scene?
↧
↧
Don't save gameobjects to scene file (No hide flags)
I am coding a terrain system that doesn't use the unity terrain engine. It works well but currently I am having problems with the terrain geometry being saved to the scene file The terrain geometry currently is over 200mb (!) when saved to the scene including all the associated splat maps and materials that go with it.
So I am looking for a way to not save the terrain tile game objects to the scene and instead load them every time unity opens by generating it from the heightmap rather than the raw meshes which uses much less data. The reason the scene cannot be such a large file is github has a 100mb limit of files and this means I cannot commit the scene to my repo, also saving the scene with the geometry in it takes longer than choosing not to save it.
Previously I was using HideFlags.DontSave however this caused issues with serialisation between the play mode and edit mode which caused the terrain geometry references to go null whenever I transitioned between these states.
Currently I have this component to place tiles in the game:
[ExecuteInEditMode]
[AddComponentMenu("Terrain/Tile Placer")]
public class TilePlacer : MonoBehaviour {
public int terrainSize = 8;
public GameObject terrainFab;
public List tiles;
public HeightMap heightMap;
public SplatMap splatMap;
public bool dirty;
public bool needsUpdate = false;
void Awake()
{
dirty = false;
DontDestroyOnLoad (gameObject);
if (tiles == null)
{
Debug.Log ("RECREATE LIST");
tiles = new List();
}
heightMap = GetComponent();
}
void OnEnable()
{
bool missingTerrain = false;
for (int i = 0; i < tiles.Count; i++)
{
if (tiles[i] == null)
{
missingTerrain = true;
}
}
Debug.Log ("MISSING TERRAIN " + missingTerrain);
Debug.Log ("TILE COUNT " + tiles.Count + " SHOULD BE: " + terrainSize * terrainSize);
if (tiles.Count != terrainSize * terrainSize || missingTerrain)
{
//StartCoroutine( PlaceTerrain() );
MarkDirty ();
}
}
public void MarkDirty()
{
dirty = true;
if (Application.isEditor)
{
Debug.Log ("call dirty");
splatMap.CreateMap(heightMap.heightGrad);
PlaceTerrain ();
dirty = false;
}
}
public void ClearTerrain()
{
Debug.Log ("CLEAR TERRAIN");
foreach(GameObject tile in tiles)
{
DestroyImmediate(tile);
}
tiles.Clear ();
}
public void PlaceTerrain()
{
ClearTerrain ();
Debug.Log ("PLACE TERRAIN");
for (int x=0; x < terrainSize; x++)
{
for (int z=0; z < terrainSize; z++)
{
//Place tile
}
}
}
}
When using HideFlags.DontSave the List tiles would reference to null objects when serializing which meant MarkDirty() would get called straight away and the whole terrain mesh would have to reload itself which again would take a lot of time to load the scene.
So is there a way to have a similar behaviour to DontSave but the gameobject still serializes but never saves to the .scene file?
Or should hideflags not mess with the serialisation and I am just using them incorrectly.
↧
About HideFlags.HideInInspector
I am currently working on a character controller using the Strategy pattern i.e. every behaviour of the said controller are abstracted into sub-Mono classes.
Example :
public class MyController : MonoBehaviour {
public AbstractMover mover;
public AbstractOrienter orienter;
public AbstractJumper jumper;
//etc.
private void Update () {
mover.Move ();
orienter.LookAt ();
jumper.Jump ();
//etc.
}
}
Everything works fine, but the inspector window get cluttered really quick with all those MonoBehaviours attached and it can get real messy real quick for a designer to setup the controller accordingly.
Hopefully, I already made my custom editor for the parent class, which handles every possible scenario in a single, clean, custom editor.
Even though the custom editor works fine, I want to make sure the designer use the parent's custom editor instead of tweaking values directly in the AbstractMover or AbstractOrienter component.
I am aware of the hideFlags property of a gameObject, but I want to set it to HideFlags.HideInInspector even at editor time.
Is there a way to do so? Because all I got right now is I set it inside the OnEnable function, whcich hides them during play mode, but show them in Editor mode...
Is there a way to set the default hideflags on a MonoBehaviour?
↧
Cant hide anything in Hierarchy IDE
Hello!
Im currently trying to hide a few objects at Hierarchy IDE and after searching in the documentation, I found this link (http://docs.unity3d.com/ScriptReference/HideFlags.HideInHierarchy.html) which should solve my problem, but after a couple of tries, I still cant manage to hide anything!
This is the code im using to attempt to hide a predetermined object:
public static void HideObjects( bool isTheSameObject )
{
ColorPicker[] getObjects = GameObject.FindObjectsOfType(typeof(ColorPicker)) as ColorPicker[];
for (int i = 0; i < getObjects.Length; i++)
{
Debug.Log ("Object Name: "+getObjects[i].name+". HideFlags: "+getObjects[i].hideFlags);
if (isTheSameObject)
{
getObjects [i].hideFlags = HideFlags.HideInHierarchy;
}
}
}
The Log tells me that the list is in fact getting the right objects. This method is being called at OnGUI by a script extended by EditorWindow.
What am I doing wrong?
Thank you so much for your help!
↧
↧
HideAndDontSave not preserve when creating Prefab
# HideAndDontSave does not work when creating Prefab...
In Unity 4.5, I have a problem where a GameObject with the flags: HideAndDontSave shows up in the hierarchy.
I have an editor extension that allows to pick a component that can be dragged into the project panel to create a Prefab. The simplified code looks like so:
void CreateDragAndDrop(string new_object_name)
{
GameObject go= new GameObject(new_object_name);
go.hideFlags = HideFlags.HideAndDontSave;
DragAndDrop.PrepareStartDrag();
DragAndDrop.objectReferences= new UnityEngine.Object[1]{go};
DragAndDrop.StartDrag(new_object_name);
MemoryPool.DelayedDestroy(go); // This service will destroy the object after it is not used for a period of time.
}
## In the Hierarchy...
When the drag is performed and ended inside the project panel, a Prefab is created but the GameObject is also visible in the hierarchy.
I can understand that the Prefab clones the 'go' but why does it now show in the hierarchy?
TAGS: Prefab, HideFlags, HideAndDontSave, DragAndDrop
NOTE: I had to put the TAGS in the text because the system does not allow me to create new tags and believe it or not _****Prefab****_ does not exist; _****HideFlags****_ does not exists; _****DragAndDrop****_ does not exists ..... This is to wonder if we are in the Unity forum !!!
↧
How to hide parent in Hierarchy and maintain child?
Hi all,
Ive been doing some research on hiding objects in the Hierarchy IDE, which now works fine as long as the object doesnt have a hierarchy of its own.
In another words, lets say I have an Object Tree, which have a child Leaf. Aside from that, lets say I have some Light at the scene. In this case, if I choose Light, I want everything else to be hiden, which is working at the moment. If I choose Leaf, then both the Leaf AND the Tree gets **displayed**, which is not what I would expect. If I choose Tree, then both the Tree AND the Leaf gets **hidden**, which also is not working properly. The proper way of it to work would be to hide everything that is not what I selected.
This is what my code looks like:
public static void HideObjects( int choice )
{
object[] allObjects = FindObjectsOfTypeAll(typeof(GameObject));
foreach(object currObj in allObjects )
{
GameObject currGo = (GameObject) currObj;
Component[] listOfComponents = currGo.GetComponentsInChildren (typeof(Component));
for( int i = 0; i < listOfComponents.Length; i++ )
{
currGo.hideFlags = HideFlags.HideInHierarchy;
if ( listOfComponents[i].GetType () == typeof(T) && mouseSelected == choice )
currGo.hideFlags = HideFlags.None;
else
currGo.hideFlags = HideFlags.HideInHierarchy;
}
currGo.SetActive (false);
currGo.SetActive (true);
}
}
What else can I do here in order to hide only a specific object even though this object is in an hierarchy? How to hide a parent without hiding its child or how to hide a child without hiding its parent?
Thank you all!
↧
OnDisable calls singleton instance, creates unwanted object + errors
So I'm just having one of those mornings, not quite grasping the best way around this.
My singleton instance invokes events to which other things subscribe. Subscribers subscribe to those events through the singleton's instance.
When I exit play mode, my subscribers call their OnDisable methods to unsubscribe, but evidently the singleton instance has already been destroyed by this point, so a new instance is created.
I figured I'd just add a DontSave hideflag to the singleton instance when it is lazy-created, but the object persists once play mode has been exited. Therefor I end up with errors immediately (before playmode has fully exited) because of null references, and must delete the unwanted instance from the scene.
I know there's gotta be a clever way I can still use this design pattern, but I'm not caffeinated enough to see it. Any suggestions would be great!
ps: my singletons are monobehaviors to conveniently expose them to the inspector
↧
Make Object Don't Save and Auto Destroy
I need to add some temporary gameobject in the scene and I don't want them to be saved.
The Hideflag.DontSave can do this but then they will not be destroyed after I load another scene.
How can I make them destroy automatically after I load other scene.
thanks!
↧
↧
How to select a hidden MeshRenderer in SceneView?
Hi all
I have a Mesh being presented in the SceneView via a MeshFilter and MeshRenderer.
The Mesh, Components and GameObject all have their flags set to HideAndDontSave. The geometry is drawn in the scene and the user is prevented from interfering with it.
I would, however, like the user to be able to select the geometry in the SceneView (by clicking or dragging a marquee, just like a normal MeshRenderer).
I am hoping to implement a callback such that when the hidden geometry is selected, I can programatically change the selection to a separate GameObject.
Is this possible?
I've been thinking about adding colliders, implementing raycasts, etc, but I don't want to interfere with physics layers. I'm also not entirely sure how to implement the mouse events in the editor.
Thanks,
Ves
↧
HideFlags.DontSave is included in build
Hey guys,
Everytime I try to build my project I get the errors below. Does anyone have any idea what could be causing this and how I could find the problem?
Thank you
An asset is marked with HideFlags.DontSave but is included in the build:
Asset: 'Library/unity default resources'
(You are probably referencing internal Unity data in your build.)
UnityEditor.HostView:OnGUI()
Building - Failed to write file: Temp/StagingArea/Data/Resources/unity_builtin_extra
UnityEditor.HostView:OnGUI()
↧
Bug with displaying components in Inspector after hideFlags.NotEditable?
Hey everyone! I've been running into a strange bug lately, maybe someone has seen something like it before.
In messing around with object hideFlags, (specifically NotEditable), I've managed to break the inspector. What appears is this:
![alt text][1]
What I expect is this:
![alt text][2]
It seems like toggling the hide flags on and off sometimes fixes the issue, but has anyone else run into this before and have a reliable fix?
Here is the code I'm using to do the toggle:
private static void ProjectWindowItem_OnGUI(string guid, Rect drawingRect) {
GameObject asset = (GameObject)AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath (guid), typeof(GameObject));
if (asset) {
if (PrefabEditor.IsEditing()) {
// Set the NotEditable flag. (| bitwise or)
asset.hideFlags = asset.hideFlags | HideFlags.NotEditable;
} else {
// Clear the NotEditable flag. (& bitwise and) (~ bitwise negate)
asset.hideFlags = asset.hideFlags & ~HideFlags.NotEditable;
}
}
}
[1]: /storage/temp/42261-screen-shot-2015-03-10-at-113753-am.png
[2]: /storage/temp/42262-screen-shot-2015-03-10-at-113803-am.png
↧
AddObjectToAsset + HideFlags.HideAndDontSave
Hello !
I have an asset file that contains an array of "abstract class".
I have read this post about serialization in unity : http://forum.unity3d.com/threads/serialization-best-practices-megapost.155352/
So my base class is abstract, derived from ScriptableObject, and have the hideFlags set to HideFlags.HideAndDontSave.
I use the method AssetDatabase.AddObjectToAsset(...) to store each object of the array in the assets file.
When I call AddObjectToAsset, Unity throws this error :
!(o->TestHideFlag (Object::kDontSaveInEditor) && (options & kAllowDontSaveObjectsToBePersistent) == 0)
But everything seems to work fine.
What does this error means, since I don't have any trouble using the assets created like this ?
Thanks!
↧
↧
Instantiating a prefab in the editor is orphaning the children of the prefabs
I have a script I wrote that I am attaching to an empty game object. This script instantiates a prefab that is dropped on it's public GameObject "instantiateObj" variable. I set the Hideflags of DontSaveInEditor and DontSaveInBuild on this instantiated game object.
The goal is to have a scene that I can see in the editor and when running the game that instantiates a prefab each time. This way, if we modify the prefab, it will always contain those changes, and we can nested prefabs.
It's almost working perfectly, but I made two test prefabs, one is made from a regular Unity UI text object, this works fine. The other is a prefab made from a regular Unity UI button, which has a child item that is a Text. When I go from editor mode to play mode, that text is dumped to the root level of my scene when his parent is cleaned up.
When I go from Play mode back to Editor mode, everything cleans up fine. Is there a difference in the way a scene gets cleaned up in the Editor versus Play mode?
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
#if UNITY_EDITOR
using UnityEditor;
using UnityEditor.Callbacks;
#endif
[ExecuteInEditMode]
public class prefabInstantiator : MonoBehaviour {
public GameObject itemToInstantiate;
GameObject instantiatedObj = null;
void Awake () {
HideFlags ourFlags = (HideFlags.DontSaveInEditor | HideFlags.DontSaveInBuild);
if(itemToInstantiate != null && instantiatedObj == null)
{
instantiatedObj = (GameObject) Instantiate(itemToInstantiate, transform.position, transform.rotation);
instantiatedObj.transform.SetParent(transform);
instantiatedObj.transform.localScale = Vector3.one;
instantiatedObj.hideFlags = ourFlags;
}
}
}
↧
AssetDatabase.IsSubAsset and HideFlags Questions
Hello.
So I have a sub-asset called [some_sub_asset] which is a part of [main_asset]. I set the hideflag for [some_sub_asset] as "HideInHierarchy", so it looks nicer in the hierarchy window (so it shows only the main asset, instead of having a whole list of subassets under the main asset).
But when I run the following code when the hideflag of [some_sub_asset] is "HideInHierarchy", Unity throws an error saying the sub-asset already exists in the main asset.
if (AssetDatabase.IsSubAsset(some_sub_asset) == false)
AssetDatabase.AddObjectToAsset(some_sub_asset, main_asset);
It seems as if *IsSubAsset(some_sub_asset)* fails if the subassets hideflag is set as "HideInHierarchy". When I set the hideflag as "None" it works as intended as *IsSubAsset(some_sub_asset)* returns true.
Since I simply wanted to change the hideflag for aesthetic purposes, I can just turn the hidelfag off and work around it but I was just wondering if anybody knew why Unity would behave this way.
Thank you!
↧
GameObject HideFlags.DontSave not working as expected
I expected the following MonoBehaviour (tested in a blank project) to cause the GameObject to which it is attached to exist in the scene in the editor but not when the game is played. This does not appear to be how it works, although the manual is not clear on this.
The manual claims that when setting HideFlags.DontSaveInEditor:
> "The object will not be saved to the> scene in the editor."
Can anyone explain to me exactly what effect setting the HideFlags like this DOES have if not what I expected? And how can I go about achieving editor-only GameObjects if not like this?
[ExecuteInEditMode]
public class HideFlagsTester : MonoBehaviour
{
private void Start()
{
this.gameObject.hideFlags = HideFlags.DontSaveInEditor;
}
private void Update()
{
this.gameObject.hideFlags = HideFlags.DontSaveInEditor;
}
}
↧
How to force object selection to be the parent of a selected object, when the selected object has HideFlags.HideInHierarchy
The scenario can be minimised to be the following:
I have an empty GameObject which has a child object in the hierarchy. The child object has a SpriteRenderer component attached, as well as an actual sprite such that it is visible in the editor.
This child object has the HideFlag **HideInHierarchy** meaning that it is still visible in the editor, however not in the hierarchy. This also means that the child object is unselectable in the editor (i.e. when trying to select the child object in the editor, Unity acts as if the child object is not there at all and tries to select whatever is behind the child object, if anything).
I wish to enforce that while the **HideInHierarchy** flag is active on the child object, the empty GameObject (the parent object) is selected when I try to select the child object in the editor.
Is there any way to achieve this behaviour?
I have tried using SelectionBase on the empty GameObject (the parent object) with no luck.
Any help is appreciated.
↧
↧
How to record hideFlags for Undo/Redo
**Greetings!**
Thank you in advance for your help.
How do you record a GameObject's hideFlag state change in the Undo/Redo system?
I have tried both Undo.RecordObject and Undo.RegisterCompleteObjectUndo, to no avail. I'm familiar with the Undo system and have recorded other actions without issue, but .hideFlag states appear to be different.
**Again, thank you so much. Be well!**
- S.
↧
Unity 5.3/5.4b: HideFlags and scripts not running?
My team is using HideFlags with an internal source control system to allow us to lock root objects in scenes from being edited. This system has worked for us through 4.0 through now, but starting with 5.3, hidden objects in Hierarchy don't have their scripts run when Play is pressed.
Essentially, using HideFlags.HideAndDontSave before would still render the objects in the game and run their scripts on play. Starting with 5.3, when play is pressed, the objects disappear from hierarchy and their scripts are *not* run. This is obviously a problem since some of our major gameplay systems are on a root GameObject "Layer_Gameplay", and when I'm trying to edit "Layer_Geometry" root gameobject, it depends on my singletons being properly initialized and run.
I've tried also using HideFlags.DontSaveInEditor, HideFlags.NotEditable and HideFlags.DontUnloadUnusedAsset, but now I have the situation where the little lock shows up in Hierarchy for these objects, but when I hit play they simply disappear (marked HideInHierarchy) even AFTER play is depressed.
Thanks!
↧
Texture2D variable causes MissingReferenceException
I've suffered a MissReferenceException when using Texture2D. With below code,
public abstract class TestBase
{
protected readonly Texture2D texture;
public TestBase()
{
texture = new Texture2D(100, 100, TextureFormat.RGB24, false);
}
public abstract void UseTexture();
}
public class Test : TestBase
{
public Test () : base()
{
}
public override void UseTexture()
{
// others
texture.Resize(80, 80);
// others code
}
}
public class TestWindow : EditorWindow
{
private static TestBase base;
[MenuItem("Tools/Test")]
private static void Init()
{
// Initialization
}
public void OnGUI()
{
if (base == null)
{
base = new Test();
}
base.UseTexture();
}
public void OnDestroy()
{
// others
Resources.UnloadUnusedAssets;
}
}
we can get a Editor Window. With the steps below, I can get MissingReferenceException, and the "texture" will be "null".
1. The "TestWindow" will be opened automatically at Play Mode;
2. Exit Play Mode, the "TestWindow" will be closed automatically;
3. Open the window from the Menu, then the Exception occurs.
Someone told me that set the hideFlags of Texture2D to be "DontSave", such as:
public abstract class TestBase
{
...
public TestBase()
{
texture = new Texture2D(100, 100, TextureFormat.RGB24, false)
{
hideFlags = HideFlags.DontSave
};
}
...
}
The error is fixed. But I cannot actually get why.
Could someone explain it?
Thanks
↧