- Home /
Is there some reference for things Unity excludes from an actual build?
For example, if I instantiate an object and then change the name of it in the hierarchy (ie changing Object.name) does this need to be removed in a production version?
If I wanted to remove " (clone)" from the name of an instantiated object this would require me to parse, split and reassign a string. It can make things much prettier when working in the editor but is completely unnecessary in a production build.
Do I have to remove this or will Unity recognize that changing the hierarchical name of an object is meaningless to the build and ignore it?
Answer by Xarbrough · Aug 26, 2017 at 10:53 PM
You don't have to remove the name change from the final build. It will simply have no meaning outside of what you define it to be. This means, the compiler will not ignore it, it will simple be there like you did it in the editor. Unity doesn't care about the object's name, so if you don't do anything with the name, other than cleaning up the hierarchy in the editor, you can wrap the name assignments in #if UNITY_EDITOR preprocessor statements, to get rid of them in the build.
Other than that, the title is a bit misleading, if my answer was the only part concerned. Beyond the name topic, there is no list of things Unity excludes by default, except all assets, which are not referenced by a scene, AssetBundle or were placed inside of the Resources folder. Script files are always included, except of course Editor scripts and code which is within #if UNITY_EDITOR or other statements, that are not true in release mode (like DEBUG). The Unity API doesn't filter anything out automatically. The only special thing I can think of is the EditorOnly tag for GameObjects, which are automatically removed on build.
Perhaps my title was a bit misleading, I apologize. I was reading about Unity excluding unused assets from the binary and general build policies and I was wondering if there was a reference for what Unity actually does during the build process.
That's when I thought about the various things you can do programmatically that have no bearing on the game itself.
Answer by Bunny83 · Aug 26, 2017 at 02:37 PM
Your question is a bit confusing. However it seems that you used "Instantiate" in some sort of editor code, which you shouldn't, at least when dealing with prefabs. To create a prefab instance during edit mode you should use the PrefabUtility: PrefabUtility.InstantiatePrefab. This will actually preserve the prefab connection.
Prefabs are a pure editor feature. At runtime there are just gameobjects. There are GameObjects serialized into a scene and there are GameObjects which aren't in a scene (the former prefabs). Any change to properties on a gameobject instance in the scene is actually stored inside the scene itself.
At runtime you can't even tell from which prefab a certain object came from. A scene is finally just composed of GameObjects, nothing more. The prefab itself isn't even included in the build when you do not have an actual reference to it in a variable. So having instances of a prefab in a scene does not make the prefab being included in the build.
Prefabs are a pure organisatorical feature of the editor. Prefabs do not save any space in a scene. So having 100 duplicates of an object in the scene or having 100 prefab instances of the same object in a scene makes no difference. The objects are actually stored inside the scene.
So to answer your question: No, it makes no difference when you change the name of objects in the scene. Actually shortening the object names will actually save a few bytes of memory ^^
I don't understand how my question was confusing at all. I am actually extremely confused by your answer.
I use instantiate to create a GameObject. For example:
GameObject foo = Instantiate(bar);
This will create a GameObject in the scene presumably called "foo(Clone)" if the prefab was named foo in the inspector.
If I get tired of looking at the word "Clone" I could do something like this
foo.name = foo.name.Split('(')[0];
This will remove the "(Clone)" in the name of the GameObject in the hierarchy.
This was just an example of something you could do programmatically that does not affect the build in any way. $$anonymous$$y question is should this be removed in a production build or does the compiler effectively ignore it?
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
How do you optimize your fonts? 1 Answer
Unity compiles assets from previous builds into an empty scene? 2 Answers
What happen to unused mesh component? 0 Answers
Compiler errors in unreferenced scripts 0 Answers