#Disable Warning "The referenced script on this Behaviour is missing"
1 messages · Page 1 of 1 (latest)
That is,
public Foo : MonoBehaviour
{
#if EXAMPLE
[SerializeField]
private int x;
#endif
}
that isn't a warning you should suppress
usually that's complaining about either a broken reference or compile errors
i don't think you should have conditional serialized fields. i don't see how that makes sense
but i guess, make sure your code is valid with conditional parts removed
This seems like a warning you should heed
I spent a long time cleaning up one of my company's projects because somebody did this based on platform and if you saved a prefab or scene on the wrong platform, all the references would get wiped. So consider this a third vote for not ignoring the warning
This is officially supported and by the documentation it sounds even recommended
Now, if this is only supported for the Editor, that I'm not sure. I'm doing the same for Server/Client and haven't had any issues.
If the variable is only used in the editor, then excluding it wouldn't be causing that warning. And if it's not only used by the editor, you shouldn't be excluding it
it sounds like you have entire scripts #if'd though
if you want to exclude certain scripts, it might be better to put them on their own GOs and use the EditorOnly tag
I do, and that is a good point
But on the other hand, I don't think the fact that Unity spits out a warning means anything because it does the same for scripts where I excluded only serialized variables. Specifically, it prints
A scripted object (probably <ClassNameHere>?) has a different serialization layout when loading. (Read 32 bytes but expected 56 bytes)
Did you #if UNITY_EDITOR a section of your serialized properties in any of your scripts?
I would probably just disregard that section of the documentation and let those scripts just have an extraneous field serialized
It's not going to be a huge problem unless you have like, millions of em
It's not millions but it's a bunch as there are a lot of things the Client for example doesn't need, that the Server may need etc. and it probably increases load times
Unity does that even in Netcode for GameObjects
https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/blob/206b610c28d0e79d85d3cee4396a2821d1cad077/com.unity.netcode.gameobjects/Runtime/Core/NetworkBehaviour.cs#L32
Maybe someone here uses that and can tell us all if you get these warnings in builds as well 😄
I've even had crashes in builds due to #ifdef of fields
I don't understand why the documentation advertises this, I have no good experiences with it; in the best case, I only see warnings like that
its possible we stumbled upon a bug of course, but still
Sounds like youre just using it in cases where you shouldn't. Ive had exactly 0 problems with it so far
I had to dig a bit, but perhaps because it was the other way around, there were some fields added instead of removed for a certain build (in a monobehaviour)