I’ve set up a few assemblies but can’t seem to find the one I needed to reference SerializedProperty (namespace UnityEditor), which is preventing me from building. I’ve tried all the editor assemblies that I can find, but no luck so far. Any help would be appreciated. Thanks.
- Welcome to the unity forum.
- What exactly did you try to achieve and what error did you get? Are you using assembly definitions?
Uhm, you can’t use SerializedProperty / SerializedObject in a built game. Those are editor only classes. They require the Unity editor to work. They can not be shipped with a game, at all. So we don’t know what you want to do here, but what you hinted at does not work at all on a fundamental level.
Fiar enough. My game builds fine normally, however I moved my scripts to a new assembly definition for testing / organization purposes. It’s complaining now that SerializedProperty isn’t something it recognizes and refuses to build. It sounds like there must be another way around this, but I’m not sure what it is.
Well it sounds like you’re trying to compile editor code into a build when you shouldn’t. So you want to make sure it isn’t built into your project. Sounds like there’s some part of your code that’s not surrounded by #if UNITY_EDITOR
pre-processors, though without knowing the exact error one can only guess.
I agree, but I’m curious to know why it builds and deploys with the default project assembly, but not when I separate my scripts into an alternate assembly. I feel like there’s a piece of the puzzle that I’m missing.
Probably because of this:
When testing in the Unity editor, Unity does automatically reference the UnityEditor assemblies when it compiles the default runtime assembly for testing. However when the default assembly is compliled for a build, none of the editor assemblies is referenced. When you setup your own assemblies, they must not reference any editor assemblies. That’s the reason why runtime and editor code should be seperated anyways.
When using assembly definition files, the manual does explain how to handle editor code. Assembly definition files should only be used for seperate modules where it makes logically sense to pre compile them into their own assembly. Such seperate modules usually have their own editor subfolder which should have its own assembly definition files to create an editor only assembly for the editor code.
Generally my approach is to have editor only versions assemblies that reference the runtime assemblies, and never the other way around.
So for example:
MyGame-Inventory
MyGame-Inventory-Editor ← has reference to MyGame-Inventory.
Any editor code in runtime assemblies is surrounded by #if UNITY_EDITOR
.
Simple and doesn’t go wrong.
Ok, there’s the piece I was missing. Thank you. It’s not in the manual (or I missed it). Where did you find this info?
For sure. A third-party asset I’m using has them mixed and I was hesitant to go in and edit it without first understanding why it was having an issue. I think Bunny83 may have revealed the information I was looking for. Thanks for assisting as well.