#Disable Warning "The referenced script on this Behaviour is missing"

1 messages · Page 1 of 1 (latest)

tall stone
#

Hi, I have a bunch of places where I may exclude some serialized variables with #if. This leads to my build logs getting spammed with the above message. Can I somehow disable that warning?

#

That is,

public Foo : MonoBehaviour
{
#if EXAMPLE
  [SerializeField]
  private int x;
#endif
}
plucky rapids
#

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

nova crest
solar pine
#

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

tall stone
#

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.

nova crest
#

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

tall stone
#

of course not

#

that would lead to a build error.

solar pine
#

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

tall stone
#

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?
nova crest
#

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

tall stone
#

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

#
GitHub

Netcode for GameObjects is a high-level netcode SDK that provides networking capabilities to GameObject/MonoBehaviour workflows within Unity and sits on top of underlying transport layer. - Unity-T...

#

Maybe someone here uses that and can tell us all if you get these warnings in builds as well 😄

pearl tree
#

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

glacial jacinth
pearl tree