Search Unity

Can't add a custom PlayableDirector to an object in scene

Discussion in 'Timeline' started by Simoense, Feb 20, 2018.

  1. Simoense

    Simoense

    Joined:
    Aug 19, 2013
    Posts:
    12
    Hello

    We are using the TimeLine in our latest project and need to extend the functionality of the PlayableDirector.
    So I made a class that derives from PlayableDirector and hooked up our own code.

    The project compiles and everything seems fine and dandy untill I try to add the script to a GameObject in a scene. I get an error saying "the script needs to derive from monobehaviour".

    I understand the message in and of itself, but why am I able to add a PlayableDirector to a GameObject but not a Class that directly derives from PlayableDirector?

    One last note : I left out the specifics of our use case by purpose. I'm not looking for an answer for our problem here. I simply try to understand what allows PlayableDirector to be added to a GameObject while a derived class can't be.
     
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    Playable Director, like other Unity behaviours and components are C# wrappers around a native implementation. All serialization is done through native code. Monobehaviours are special behaviours that allow for serialization of C# defined data, so all components written in script are assumed to (and need to) derive from monobehaviour.

    Even if the UI allowed your derived class, any data you added to your class would not get serialized.
     
    Simoense likes this.
  3. Simoense

    Simoense

    Joined:
    Aug 19, 2013
    Posts:
    12
    Thanks for the clarification.

    I made a MonoBehaviour containing our custom behavior that requires a PlayableDirector and controls it.
    This does the job but it feels a bit convoluted.