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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

File is updated with TrackAsset.muted

Discussion in 'Timeline' started by kumamoto10, Sep 12, 2019.

  1. kumamoto10

    kumamoto10

    Joined:
    Jun 25, 2018
    Posts:
    18
    If you mute with TrackAsset.muted while playing Unity, the playable file will be updated.
    Is there a good way to mute the application only and not update the file?
     
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    There is no specific runtime mute feature, although that has been requested. One (inefficient) way to accomplish it is to mute the track, then call playableDirector.RebuildGraph().

    A more complicated, but efficient method you can try is removing the binding from the playable graph. This only works if the track is bound to an object (so it wouldn't work for control tracks).

    There are separate code paths for Animation, Scripts (i.e. custom) and Audio needed. But removing the binding on Audio won't work because unbound audio tracks still play (just without a 3D source).

    For script tracks, they will still run and require that the custom script track properly handles a null passed into the userdata field in ProcessFrame();


    Code (CSharp):
    1.        static void MuteAnimTrack(PlayableDirector director, Animator animator)
    2.         {
    3.             if (director == null || !director.playableGraph.IsValid())
    4.                 return;
    5.  
    6.             for (int i = 0; i < director.playableGraph.GetOutputCountByType<AnimationPlayableOutput>(); i++)
    7.             {
    8.                 var animOutput = (AnimationPlayableOutput) director.playableGraph.GetOutputByType<AnimationPlayableOutput>(i);
    9.                 var binding = animOutput.GetTarget();
    10.                 if (binding == animator)
    11.                     animOutput.SetTarget(null);
    12.             }
    13.         }
    14.  
    15.         static void MuteScriptTrack(PlayableDirector director, UnityEngine.Object target)
    16.         {
    17.             if (director == null || !director.playableGraph.IsValid())
    18.                 return;
    19.  
    20.             for (int i = 0; i < director.playableGraph.GetOutputCountByType<ScriptPlayableOutput>(); i++)
    21.             {
    22.                 var scriptOutput = (ScriptPlayableOutput) director.playableGraph.GetOutputByType<ScriptPlayableOutput>(i);
    23.                 var binding = scriptOutput.GetUserData();
    24.                 if (binding == target)
    25.                     scriptOutput.SetUserData(binding);
    26.             }
    27.         }
    28.  
     
  3. kumamoto10

    kumamoto10

    Joined:
    Jun 25, 2018
    Posts:
    18
    Thank you.
    It was helpful.