Search Unity

Timeline and Cinemachine with data-driven objects

Discussion in 'Timeline' started by Lysander, Oct 17, 2017.

  1. Lysander

    Lysander

    Joined:
    Feb 24, 2013
    Posts:
    1,588
    Our project is almost entire data-driven, which means we store pretty much every aspect of all of the various objects in databases, then either redirect data requests in the scene to those database entries, or construct GameObjects programmatically using the databases as a guide to reach the proper result. Characters, vehicles, in-game objects, pretty much everything is all are stored and generated using this method, and MonoBehaviours / GameObjects are minimized as simply the visual aspects as seen / interacted-with in the game. GameObjects are never used to store unique information other than the general behaviour of the object type, so we require few prefabs.

    This approach has worked great so far, but now that we're getting into creating cutscenes, it's turned into a bit of an issue. For instance, say I have to create a cutscene using specific characters standing around talking to eachother and interacting, normally you would just use prefabs that have all of the data needed for those specific characters in the scene, but in our case we have no prefabs for specific characters, just one prefab for ALL characters. While I could obviously make new prefabs, it would break the data-driven approach we've used for everything else up to this point, and make the project far more difficult to maintain.

    My strong preference is the ability to break the entire timeline system down into smaller pieces (prefabs of actions/events) and then save those to a database to be reconstructed later programmatically. This is the way our level editor system works, by having only a few prefabs for specific types of objects with unique interactions, then constructing the level with those tiny prefabs and saving the specific models / collider dimensions / layer data we select for them to database entries so that they can be reconstructed when the level is actually needed. We can load the entire level with a button from the database entries for all of the components (little "c") that make up the level, and if changes are made we can then save those changes out to the database again. I'd like to do the same with the timeline, if at all possible- construct it exactly how you'd expect to construct a cutscene, but then save it out with the press of a button and reconstruct it later from data (data that may have changed, in the meantime, like the specific character models and such).

    The API for timeline seems extremely limited so far, so if this approach isn't possible, I'd like to be able to construct cutscenes using temporary stand-ins for all GameObjects, so that things can be edited in the timeline using dummies, and the real deal is pulled from the databases at runtime and the GameObjects constructed programmatically.

    If anyone has experienced similar difficulties and has some advice/tips on programmatic timeline editing using either of the methods listed above, or any other methods you can think of to simplify things and get them working, I'd be eternally grateful. I'm having some difficulty abstracting the process in any meaningful way, since so much of Timeline appears to require the need for specific GameObject references in order to change/interact with them.

    Cheers!
     
    Last edited: Oct 17, 2017
  2. TimmyTheTerrible

    TimmyTheTerrible

    Joined:
    Feb 18, 2017
    Posts:
    106
    If i understand you, your asking if you can replace the dummy objects you animated in a timeline, with other objects when you want to play the timeline. I'm no expert, but you can replace the bindings before playing the timeline in script.

    Code (CSharp):
    1.  
    2.  
    3. public List<GameObject> new_bindings = new List<GameObject>();
    4.  
    5. private void SetNewBindings()
    6. {
    7.             var timeline_Asset = playableDirector.playableAsset as TimelineAsset;
    8.            
    9.             if (timeline_Asset == null)
    10.                 return;
    11.  
    12.             for (var i = 0; i < new_bindings.Count; i++)
    13.             {
    14.                 if (new_bindings[i] != null)
    15.                 {
    16.                     var track = timeline_Asset.GetOutputTrack(i);
    17.  
    18.                     if (track != null)
    19.                         playableDirector.SetGenericBinding(track, new_bindings[i]);
    20.                 }
    21.             }
    22. }
    23.  
    24.  
     
    senkal_ and seant_unity like this.