Create a PlayableGraph with different outputs
Learn how to create a PlayableGraph with two different playable output types.
읽는 시간 2분최근 업데이트: 10일 전
This example demonstrates how to create a with two different playable output types: an and an . This example also demonstrates how to play an through an connected to an .
PlayableGraphAudioPlayableOutputAnimationPlayableOutputAudioClipAudioClipPlayableAudioPlayableOutputPrerequisites
Before you use the script in your project, your project must have the following:
DifferentOutputs- A GameObject, such as a cube or a capsule. You don't need to manually add an Animator component or an Audio Source component to this GameObject. The attribute adds these components if they're not present.
RequireComponent - An animation clip that animates the properties of the GameObject. For example, an animation that changes the position and rotation of a GameObject. If your project doesn't have an animation clip, you won't be able to select a clip and nothing will happen at runtime.
- An audio clip. If your project doesn't have an audio clip, you will not be able to play audio while the GameObject animates.
Add and run the script
To use the script in your project, follow these steps:
DifferentOutputs-
Add a script component to your GameObject. Name the script fileand use the following code:
DifferentOutputs.csusing UnityEngine;using UnityEngine.Animations;using UnityEngine.Audio;using UnityEngine.Playables;[RequireComponent(typeof(Animator))][RequireComponent(typeof(AudioSource))]public class DifferentOutputs : MonoBehaviour{ public AnimationClip animationClip; public AudioClip audioClip; PlayableGraph graph; void Start() { // Create and name the graph. graph = PlayableGraph.Create("DifferentOutputs"); // Create the outputs. var animationOutput = AnimationPlayableOutput.Create(graph, "Animation", GetComponent<Animator>()); var audioOutput = AudioPlayableOutput.Create(graph, "Audio", GetComponent<AudioSource>()); // Create the playables. var animationClipPlayable = AnimationClipPlayable.Create(graph, animationClip); var audioClipPlayable = AudioClipPlayable.Create(graph, audioClip, true); // Connect the playables to an output. animationOutput.SetSourcePlayable(animationClipPlayable); audioOutput.SetSourcePlayable(audioClipPlayable); // Play the Graph. graph.Play(); } void OnDisable() { // Destroys all Playables and Outputs created by the graph. graph.Destroy(); }} -
In the Script component, select the Animation Clip and Audio Clip that the PlayableGraph will play at runtime.
-
Select Play to switch the Editor to Play mode.
-
If you have installed the PlayableGraph Visualizer package, selectto display the PlayableGraph.
MultiOutputSample

The PlayableGraph generated by the DifferentOutputs script.