Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question No longer possible to use define symbols around serialized classes

Discussion in '2020.1 Beta' started by StaggartCreations, May 2, 2020.

  1. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,211
    I have a setup for several scripts where they're wrapped in a define symbol. This is to ensure no compilation errors are thrown for their base class, if it is not present, but still allowing it to be serialized. Like so:

    Code (CSharp):
    1. #if !POST_PROCESSING_INSTALLED
    2.     public class PostEfectSettings : ScriptableObject {}
    3. #else
    4.     [Serializable]
    5.     [PostProcess(typeof(EffectRenderer), PostProcessEvent.AfterStack, "Post processing effect", true)]
    6.     public sealed class PostEfectSettings : PostProcessEffectSettings
    7.     {
    8.     }
    9. #endif
    This has worked up to 2019.3, but since 2020.1 the following warning will be thrown:
    The result is that the ScriptableObject cannot be serialized, as if the file and class name mismatch.

    What is the reason for enforcing this? Do I now need two "PostEfectSettings" files, where one is compiled out and the other one isn't?
     
    QFSW likes this.
  2. jasonboukheir

    jasonboukheir

    Joined:
    May 3, 2017
    Posts:
    81
    Have you tried defining them in different files? Does that work?
     
  3. joepl

    joepl

    Unity Technologies

    Joined:
    Jul 6, 2017
    Posts:
    87
    In this case, the script parsing code currently requires these classes to live in separate files. Placing them in separate files with the appropriate #if statements should fix the issue. Apologies for the necessary changes.
     
  4. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,572
    Thanks for your answer. Does "currently" mean "it's just for now, we're going to fix it during 2020.1 beta cycle"?

    In order to make serialization work, UnityEngine.Object derived classes must live in a file that uses the class name as filename. Storing those classes in separate files would then require them to be placed in different folders, because the file system does not allow to have files with identical filenames in the same folder.

    It doesn't sound like an attractive long-term workaround for me.
     
    MegamaDev and Havokki like this.
  5. joepl

    joepl

    Unity Technologies

    Joined:
    Jul 6, 2017
    Posts:
    87
    It looks like this is being looked into to change. I'm not certain it will make it in for the 2020.1 beta cycle but it should get done soon. I'll follow-up on this thread when I know when it lands.
     
  6. Ignas83

    Ignas83

    Unity Technologies

    Joined:
    Mar 26, 2013
    Posts:
    28
    I've copy pasted your code to a new file and it's importing fine without any warnings. Is there anything else in the file? Is the file named PostEfectSettings.cs (note you've misspelled word effect)? What exact version of Unity are you on?

    Bug report with small repro project would be ideal though.