Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Feedback Please split ISerializationCallbackReceiver into two separate interfaces

Discussion in '2020.1 Beta' started by Ardenian, Mar 4, 2020.

  1. Ardenian

    Ardenian

    Joined:
    Dec 7, 2016
    Posts:
    313
    Please split the interface ISerializationCallbackReceiver into two separate interfaces ISerializationOnBeforeReceiver and ISerializationOnAfterReceiver.

    The reason behind this is simple. Often, as a developer, you only need to react to one of the two callbacks in your component, but the interface forces you to implement both, leaving one method completely empty.

    One example is the transformation of serializable objects into objects that are not supported by the serialization system of Unity. One might want to transform these objects with no intention of changes being propagated back, which is especially true for runtime, aiming to change the representation of an object into a more fitting object to optimize certain scenarios.

    Splitting the interface into two ones could provide a performance boost after optimization, similar to how Unity encourages that empty
    Update()
    and
    Start()
    should be removed because they drain performance even if they do nothing.

    You would probably end up with something like, allowing the change to be backwardly compatible:
    Code (CSharp):
    1. public interface ISerializationCallbackReceiver : ISerializationOnBeforeReceiver, ISerializationOnAfterReceiver
     
    TextusGames likes this.
  2. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    3,136
    I've forwarded your feedback to the devs and they agreed that it makes sense. They couldn't commit to implementing it yet but are aware of the request.
     
    Ardenian likes this.
  3. Ardenian

    Ardenian

    Joined:
    Dec 7, 2016
    Posts:
    313
    Thank you for forwarding it, if I stumble upon community examples during my work where the current problem of being forced to implement both methods is highlighted, I make sure to post them here. I not only stumbled upon them in the past myself, I did see them in shipped code that I bought, just happen to not remember where exactly, even after small searches not finding them.