- Home /
Is Reset() only called in the editor?
In Unity we have Reset()
method for setting default values of the components. It is called after they are added or when "reset" button is clicked in the editor. I have some questions regarding its usage:
Is this method only called in the editor and never in the built game?
Does this method get built along with other code, or is it stripped from the compiled binaries?
Suppose I have written some editor utilities at put them inside an
Editor
folder, so they are now in a separate assembly and are never included in the builds. This is nice, because it is impossible to accidentally use these utilities in runtime code (the game just won't compile). But what if I want to use them insideReset()
, which is supposed to be an editor-only method? Can this be done? Since the editor assembly is not included in the project, any classed fromEditor
folders are also not available.
Any tips are appreciated!
Answer by CodesCove · Jun 28, 2020 at 09:40 PM
1) only in Editor mode (never in builds): https://docs.unity3d.com/ScriptReference/MonoBehaviour.Reset.html
2) I think it will not get stripped. Enclose the Reset() in #if UNITY_EDITOR .. #endif preprocessor directive to strip it out of builds
3) use the above directive and it will not cause problems..
Your answer
![](https://koobas.hobune.stream/wayback/20220613001930im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Virtual Reality not supported!! 1 Answer
Toggle bool reset after using DestroyImmediate (On Editor Script) 0 Answers
C# dll "MissingMethodException" - Before first recompile 1 Answer
Large serializable field in a MonoBehaviour causing poor performance in Inspector 1 Answer
EditorJsonUtility.FromJsonOverwrite - "Not implemented yet" error 0 Answers