Resolve 'UnityEditor' error
Happy New Year everyone.
Help me with this question, I have the DayNightGradient package which is having an error when im building my project.
It says the type or namespace name UnityEditor could not be found.
I know that types like this must be on Editors folder But if i move that script to Editors folder, the references and many things goes wrong
So I need a resolution for this an in easiest way. Please help me out on this on, this is a long story with this problem.
If you need, the link to DayNightCycle project is here: GitHub link
Answer by Larry-Dietz · Dec 31, 2017 at 07:03 PM
Editor scripts are for use in the editor only. Nothing editor related will end up packaged in the build, so if you have actual game code dependent on an editor script, you need to refactor that code. Editor scripting is only to help you get the object set up. Not to actually do anything at run time. Even if you managed to get everything straightened out with putting it into an editor folder, it wouldn't be included in the actual build.
-Larry
So you mean, that every script with the "using UnityEditor" must be only in Editors folder? Or we have some options to make it works without this folder? Can you check this asset that i have linked above, if you will try to build a project, it will type an error for 1 script. Its strange because it is the original asset without any of my changes, please if you know what to do please tell me.
Ok, I took a look at the DayNightGradient script, and all the editor stuff in the script is wrapped in a preprocessor directive to NOT be included when built, so you should be good on that point.
I would recommend wrapping the using statement the same, and see if you can build, and that the build works as expected.
i.e.
using UnityEditor;
becomes
#if UNITY_EDITOR
using Unity_Editor;
#endif
Give that a shot, and let me know how it works.
Thats strange, i have changed "using UnityEditor" on DayNightCycleGradient script to what you said And so the script is not giving an error on this one But giving 3 errors on the createPlane$$anonymous$$esh script With the same UnityEditor but not on the begining, its starting with the "mesh m" I hope there is a resolve for this one..:)
Or you mean I need to copy my script on editors folder?
For this particular script, you don't need it in an editors folder. He just has some code in here that is called from another script that IS in an editor folder, and that script will only ever be called when running in the editor.
So removing that using statement from the build (which using the code I put above will do) should help you get it built. unless you have added any additional code that uses something from UnityEditor.
If that is the case, post the code you added using the UnityEditor namespace, and we can see what needs to be done.
Thank you for your help I checked #if UnityEditor thing and it helped Im just added this at the start and the end of the script And it works You can look at this in here! :) thank you again