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

2017.1.0b1: BuildPipelineInterfaces Feedback

Discussion in '2017.1 Beta' started by Peter77, Apr 15, 2017.

  1. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,609
    I was looking at the new BuildPipelineInterfaces and ran into some issues, because I expected them to work differently.

    Issue #1
    My initial thought was, if I implement such interface, it's called on all objects that implement such interface, that exist at the time when the callback fires.

    I couldn't find any explanation in the documentation, but after some trial & error, it rather seems to work like this:
    Unity creates a new object instance of every class that implements such BuildPipeline interface and calls the corresponding method on it.

    Before I knew that, I implemented the IActiveBuildTargetChanged interface in an derived UnityEditor.EditorWindow class, where I need to adjust things when the build-target is changed. However, switching the build-target caused Unity to create a new MyWindow instance (derived from EditorWindow), rather than calling the method on the existing instance (the already opened window).

    MyWindow must be instantiated using the ScriptableObject.CreateInstance method instead of new MyWindow.
    UnityEditor.EditorWindow:.ctor()
    MyWindow:.ctor()
    UnityEditor.Build.BuildPipelineInterfaces:InitializeBuildCallbacks(BuildCallbacks)



    The EditorUserBuildSettings.activeBuildTargetChanged delegate is marked as deprecated in 2017 already, but I don't see how I can implement my existing functionality with the new approach, without writing a lot more code for it.

    In order to get that working with the new BuildPipelineInterfaces, it seems I have to...
    1. Create a class that implements IActiveBuildTargetChanged
    2. Find my window instance when Unity fires the callback
    3. Implement a method that the IActiveBuildTargetChanged implementation calls on my window
    This sounds a lot more complicated than simply subscribing to a delegate, as it worked before.


    Issue #2
    If I implement the IActiveBuildTargetChanged in an abstract class, Unity outputs an error:

    MissingMethodException: Cannot create an abstract class 'AbstractWindow'.
    System.Activator.CheckAbstractType (System.Type type)
    System.Activator.CreateInstance (System.Type type, Boolean nonPublic)
    System.Activator.CreateInstance (System.Type type)
    UnityEditor.Build.BuildPipelineInterfaces.InitializeBuildCallbacks (BuildCallbacks findFlags)

    Could you please implement to skip abstract classes and call the interface method on the derived class (non-abstract) instead:
    (Case 901915) 2017.1.0b1: IActiveBuildTargetChanged: Cannot create an abstract class


    Issue #3
    All BuildPipelineInterfaces require to implement the IOrderedCallback interface. Which means I can't implement, for example, IPostprocessBuild and IPreprocessBuild with different callbackOrder's on the same class. I need to implement them via two classes instead.

    I don't want to judge whether it's good or bad, it's just something that doesn't seem to be possible with the current design.
     
    Last edited: Apr 16, 2017