[Unity] Dynamically create Timeline resources (.playable)

            var asset = TimelineAsset.CreateInstance<TimelineAsset>();
            AssetDatabase.CreateAsset(asset, "Assets/test111111.playable");
            var track = asset.CreateTrack<DialogueTrackLua>(null, "tt");
            var clip = track.CreateClip<DialogueClipLua>();
            //var clip = track.CreateClip<Talk>();
            //clip.displayName = "QAQ";
            AssetDatabase.SaveAssets();

Precautions

1. AssetDatabase.CreateAsset must be performed at the top, that is, after CreateInstance<TimelineAssets>, otherwise it may cause data loss problems (maybe data loss of value types)

2. Fill in null for the parent track of the first track

3. After the clip is created, the asset member of the Clip cannot be assigned at will (it is better not to create an asset and assign it by yourself) it has its own asset, which will cause Clip exception!

For example, the following Sao operation will cause a Clip exception

var baseClip = PlayableAsset.CreateInstance(luaScriptName);
timelineClip.asset = baseClip;

These problems caused me for a week! PS: PlayableAsset.CreateInstance<T>(string name); It should be like this, the above will report an error

Guess you like

Origin blog.csdn.net/qq_39574690/article/details/112461733
Recommended