Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor-only fields in GuidReference aren't allowed #2

Closed
SilentSin opened this issue Jul 19, 2018 · 3 comments
Closed

Editor-only fields in GuidReference aren't allowed #2

SilentSin opened this issue Jul 19, 2018 · 3 comments

Comments

@SilentSin
Copy link

There's a problem in GuidReference.cs:

#if UNITY_EDITOR
// decorate with some extra info in Editor so we can inform a user of what that GUID means
[SerializeField]
private string cachedName;
[SerializeField]
private SceneAsset cachedScene;
#endif

This will still include serialized data for those fields in a build and will throw warnings in the log about the serialized data not matching the class.

Being able to make editor-only fields like that would be super useful but would require low level engine modifications. Even if we have to write [SerializeField(EditorOnly = true)] or something since reflection can't detect the #if on its own. Otherwise the build process would need to re-serialize everything based on the runtime class structure (possible, but would extend build times).

The only way to currently serialize editor-only data on a component is to have a whole separate component and set its hideFlags to DontSaveInBuild. Also note that this approach doesn't work if the component is saved in a prefab because the hideFlags get ignored.

@william-w-armstrong
Copy link
Contributor

I do not see anything in the log in a development build in Standalone in 2017.4
This should, at the very least, remove the memory cost at runtime, unless I am very much mistaken.

@SilentSin
Copy link
Author

No, you're right, it seems they did implement re-serialization based on the runtime class structure since I last checked (which was like, back in Unity 4 or something) because I'm not getting the same old error and I can't detect any difference in build size or runtime resource load time when creating a float[1024 * 1024] in a #if UNITY_EDITOR region (which does clearly affect the size of the prefab asset in the editor).

And perfect timing too. I was just about to implement a rather hacky workaround for serializing editor-only fields.

@SugoiDev
Copy link

This is great news! I also had my fair share of workarounds for that issue.

I remember only ever actually seeing the warnings on WebGL builds. It would spam the console hard when the serialized layout didn't match between the editor and a build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants