Search Unity

Resolved Recorder clips added to the timeline by script in edit mode are reset in play mode

Discussion in 'Audio & Video' started by melting_pot, May 25, 2021.

  1. melting_pot

    melting_pot

    Joined:
    Mar 2, 2018
    Posts:
    9
    Hi, not sure if this is a timeline issue or recorder issue so I'll start here...

    I have a script to add a recorder track to the timeline and fill it with some recorder clips (all done in edit mode).
    The script configures each clip, setting the timings, capture settings and output settings.
    Everything is generated as expected by the script, but when entering play mode some of the settings are reset to defaults. This does not happen for clips that I make manually without the script.

    Could it be a problem with the way I am configuring the clips in my script? Any help appreciated, thanks!

    This is how I'm configuring the clips. The generic clip properties are retained, but the animation recorder specific settings are not.

    Code (CSharp):
    1. TimelineAsset ta = (TimelineAsset)playableDirector.playableAsset;
    2. RecorderTrack rt = ta.CreateTrack<RecorderTrack>("new track");
    3.  
    4. // These settings are retained
    5. TimelineClip newClip = rt.CreateClip<RecorderClip>();
    6. newClip.displayName = "new clip";
    7. newClip.duration = 5;
    8. newClip.start = 0;
    9.  
    10. RecorderClip rc = (RecorderClip)newClip.asset;
    11. // These settings are NOT retained
    12. rc.settings = ScriptableObject.CreateInstance<UnityEditor.Recorder.AnimationRecorderSettings>();
    13. var animSettings = rc.settings as UnityEditor.Recorder.AnimationRecorderSettings;
    14. animSettings.AnimationInputSettings.Recursive = true;
    15. animSettings.AnimationInputSettings.ClampedTangents = true;
    16. animSettings.AnimationInputSettings.SimplyCurves = 0;
    17. animSettings.AnimationInputSettings.AddComponentToRecord(typeof(Transform));
    18. animSettings.AnimationInputSettings.AddComponentToRecord(typeof(Camera));        
    19. animSettings.AnimationInputSettings.gameObject = animatedObject;
    20.  
    21. rc.settings.Take = 1;
    22. rc.settings.FileNameGenerator.ForceAssetsFolder = true;
    23. rc.settings.FileNameGenerator.FileName = "new_shot";
     
  2. melting_pot

    melting_pot

    Joined:
    Mar 2, 2018
    Posts:
    9
    After checking the code from the Recorder package, I've fixed my problem by adding these lines after the above:

    Code (CSharp):
    1. AssetDatabase.AddObjectToAsset(rc.settings, rc);
    2. AssetDatabase.SaveAssets();