Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Question Mute Group Track via script

Discussion in 'Scripting' started by enemali, Jun 10, 2024.

  1. enemali

    enemali

    Joined:
    May 29, 2017
    Posts:
    21
    Im looking for a way to mute a Track Group via script , so far what i was able to do is to loop through each tracks and mute them, how do i mute the parent Track Group by it name.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Playables;
    3. using UnityEngine.Timeline;
    4. public class timeLineMuteUnMute : MonoBehaviour
    5. {
    6.     public PlayableDirector director;
    7.     public TimelineAsset timelineAsset;
    8.     // Start is called before the first frame update
    9.     void Start()
    10.     {
    11.         MuteTracksInGroup("MY-GROUP");
    12.     }
    13.     void MuteTracksInGroup(string groupName)
    14.         {
    15.         director.playableAsset = timelineAsset; // Ensure director uses the TimelineAsset
    16.  
    17.         // Loop through all tracks in the TimelineAsset
    18.         foreach (var track in timelineAsset.GetOutputTracks())
    19.         {
    20.             track.muted = false;
    21.         }
    22.  
    23.         director.RebuildGraph(); // Rebuild the playable graph to reflect changes
    24.         }
    25.            
    26.  
    27. }