Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

SceneAsset on PlayableTrack

Discussion in 'Timeline' started by Rodolinc, Jan 28, 2019.

  1. Rodolinc

    Rodolinc

    Joined:
    Sep 23, 2013
    Posts:
    63
    Is it possible to have a SceneAsset as a TrackBindingType ? Its possible in the editor I already tested it and worked but the moment I tried to build the app, wasn't possible to compile (gave me an error on a line that looked like this: [TrackBindingType(typeof(UnityEditor.SceneAsset))] )
    I came with a partial solution using Object instead, drawback is that in the editor the user can drag any file not just scenes.
    Then found out this great SceneReferencer and changed the line to [TrackBindingType(typeof(SceneReference))] but now I cant convert the type as you can see in line //13:

    Code (CSharp):
    1. [TrackBindingType(typeof(SceneReference))]
    2. public class SceneControlTrack : TrackAsset
    3. {
    4.     public override Playable CreateTrackMixer(PlayableGraph graph, GameObject go, int inputCount)
    5.     {
    6.         PlayableDirector director = go.GetComponent<PlayableDirector>();
    7.         var binding = director.GetGenericBinding(this);
    8.  
    9.         foreach(var c in GetClips())
    10.         {
    11.             var myAsset = c.asset as SceneControlAsset;
    12.             if (myAsset != null)
    13.                 myAsset.binding = (SceneReference) binding;//LINE 13 shows: "cannot convert type Object to SceneReference" error
    14.         }
    15.  
    16.         return base.CreateTrackMixer(graph, go, inputCount);
    17.     }
    18. //...
    edit:
    This is the error I get if I leave UnityEditor.SceneAsset when trying to Build.

    error CS0234: The type or namespace name 'SceneAsset' does not exist in the namespace 'UnityEditor' (are you missing an assembly reference?)
     
    Last edited: Jan 28, 2019
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    So SceneAsset is part of the UnityEditor, so you can't get a binding in a player. SceneReference isn't a UnityEngine.Object, so it it can't go through the generic binding system.

    What you could do is add a sceneReference field to your SceneControlTrack. Instead of a binding, it's a field on the track. You'll need to remove the track binding and instead set it with the inspector after selecting the track.
     
    Rodolinc likes this.
  3. Rodolinc

    Rodolinc

    Joined:
    Sep 23, 2013
    Posts:
    63
    Perfect, that worked, thanks a lot. And thanks for clarifying the difference in object types.