Ok so I'm very new to Unity (most time spent in Unreal) so this may need to be explained to me like I'm 5 but I've seen a hundred decade old forum posts about this issue and every solution suggested is wildly different and has never worked - so I'm asking here. Right now I have an extremely primitive version of my project and would like to export it simply to test how it builds, since I've never built a unity project before. However, when I build the project, I instantly get these errors relating to the first few lines in a couple scripts, relating to the references some scripts need. I can clearly see Visual Studio already has the relevant references but it seems to still be giving me errors about how it doesn't recognize them. ALSO: I even tried just commenting out all the lines it's talking about and it actually built with no errors logged, but when you play, every game object disappears the moment you interact with it. AND, after doing this, the game works completely as intended in the editor, which I don't even understand how that's possible. I really have no idea what's happening here lmao, but I assume commenting out these lines would be related. How do I build this stupid project - haven't had any luck looking through forums or videos so any help would be greatly appreciated.
#The type or namespace name 'UI' does not exist in the namespace 'UnityEditor'
1 messages · Page 1 of 1 (latest)
You cannot use any UnityEditor code in a build
..........
well idk how i missed that before lmao
what am i supposed to do then
If you have a script that uses any UnityEditor namespace, it needs to be put in a folder named Editor to exclude it from the build, or put in an assembly definition that isn't included for your platform
Or excluded by using a conditional compilation directive
https://docs.unity3d.com/2023.2/Documentation/Manual/PlatformDependentCompilation.html
is this folder already pre-made? or do i need to make it and put it somewhere myself
Any folder named exactly Editor will be excluded from the build
ok interesting
so just like this?
Well, if you want the files to be used in the project you'll want it to be in the Assets folder
oop
so when i build the project with these scripts, is everything related to them just not going to work then?
how am i supposed to do stuff without using UnityEditor references
They'll be excluded entirely. It will build as if they did not exist, but when you have the project in the editor, you can still use the custom editors and things you've defined
What would they even do in a built game? There's no editor for them to affect
i think im getting the picture but why would you have references that only work in editor
how do i get references that allow me to test functions in editor while still letting me build the same functions
is there some FAQ somewhere i should read about this
The entire purpose of the UnityEditor namespace is to do things in the Unity Editor. As in the actual Unity program itself. There is no editor in a built game
alright i see but what namespace am i supposed to use then
when i remove references to the unity editor namespace all relevant files using the namespace stop working in the build
if you must have editor references in non-editor scripts, you'd use conditional compilation, ex
#if UNITY_EDITOR
#endif
to ensure that code is only included in the editor
There's not an "alternative", you're supposed to exclude things that use UnityEditor. They affect the Unity program itself, not your actual game being built in it.
The "alternative" is don't
alright lemme try this
i appreciate the help btw
What exactly are using the UnityEditor namespace for? It's really meant for making editor tools and the like. I have a feeling that you are just using the wrong namespace
i probably am, but upon making the script it autogenerated these lines in most
also not sure if this is related to the original problem anymore, but excluding lines related to the unityeditor namespace just results in the same thing (random object disappearing) as commenting these lines out manually, what is the issue here that im missing
either they were autogenerated or i put them in manually because it wouldnt recognize commands i knew should work until i put it in because i am a scrub
What is disappearing
the player is invisible, and the cubes (they represent vending machines you get stuff out of lol) disappear once you interact with them, and the little moving guys disappear after they do one of their automatic functions (farm money for you) - below video is what its supposed to look like
Are the objects that are disappearing in the UI or in world space
world space, despite the original problem also relating to UI elements, everything UI related works as normal
also strange because the cubes outright de-exist rather than being invisible, while player control works totally fine despite not being visible
player collision and physics still intact
I notice that you seem to have a lot of error shaders, maybe replacing them with one that works in your render pipeline would be best
unless these are compatible shaders and you've specifically turned them pink
that makes sense, but where do you see that? someone im working with has been working on a custom shader for a bit and she is also new to unity
Pink means shader error
Which usually means incompatible with your current render pipeline
oh wtf i thought it just meant no texture
that was the case before we started implementing the shader so idk how there could be shader errors before i did anything with shaders
ok you were right about the shader stuff, all the elements with the incompatible material started working when i used a material that worked, which makes sense in the case of the player but i dont get why it causes the vending machine to not disappear
whatever i guess
all seems to be well except for one small thing which hopefully i can figure out
thanks so much for ur help