Siccity / SerializableCallback

UnityEvent and System.Func had a child
MIT License
359 stars 53 forks source link

Inclusion of #if UNITY_EDITOR on variables causes build crash. #8

Closed kearan-petersen closed 5 years ago

kearan-petersen commented 5 years ago

This is a very specific case, and fortunately is an easy fix. When creating lists of serializable callbacks, and only when adding more than one method call to the list, causes builds to crash. When adding only one method call, there is a hint in the player log that something is wrong, but Unity is able to save itself.

The issue has to do with how Unity serializes class variables, and then deserialize them within a build. I am not 100% sure, but my best guess is due to the build occurring within the editor itself, any variables that are within a #if UNITY_EDITOR block will be included in the final build's class signatures. However, when deserializing the classes, these variables are skipped due to being within the #if UNITY_EDITOR block, resulting in memory misallocation, and an eventual crash.

While it is good practice to exclude any unused variables from the final build, I think currently it is not possible to do so with how Unity handles serializing and deserializing. I have run into this same issue with my own code, and simply removing the #if UNITY_EDITOR blocks from any variables fixes the issue.

Siccity commented 5 years ago

Thanks. Hopefully that solves the build errors some people have complained about in the past :)