We can now trigger cut scene using a trigger volume - oh the possibilities!
I have play on awake turned off on the Playable Director, but it is still running through the animation when I start the game. Not sure what is happening here… I am using a newer version of Cinemachine, 2.5 I believe, but the play on awake seems to be the same. Any ideas?
[Question]I’m having the same problem: the sequence plays when I start the game even though Play on Awake is unclicked. What can I do?
[Solution] I had my box collider partly in the ground. So the terrain was triggering it!
Thanks for sharing your solution, that was really helpful! I had the same issue.
My solution was to wrap the Play() in an if statement:
This way I can use it in places where there may be enemies or other objects (eg pick ups, etc) and they can pass through without triggering anything, either.
Hello,
Hopefully someone sees this.
My understanding was that when the player’s capsule collider enters the trigger volume of the intro sequence’s box collider, the OnTriggerEnter is called.
So, I tried to trigger the intro sequence without the RigidBody component in the Intro Sequence gameobject. But it did not work. Does anyone know why the absence of a Rigidbody doesn’t allow trigger events?
Thanks!
The RigidBody is the component that actually calculates and reports colissions and triggers. Without a RigidBody, no physics will happen. One or both GameObjects with colliders must have a RigidBody.
Remember to only run it once. Here’s what I did.
Disabling the collider (while only a minor performance improvement in this very simple scene) I feel is a good practice if you only need something to run once.
In a more complex, more active scene, disabling the collider means it’s no longer part of the physics calculations and could be a very nice performance benefit. It also means this method never even gets called again but the real benefit is in the physics code you don’t see running. Very useful if you have lots of loot, etc.
public class CinematicTrigger : MonoBehaviour
{
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Player"))
{
GetComponent<PlayableDirector>().Play();
GetComponent<Collider>().enabled = false;
}
}
}
I did the same. Also, instead of checking the player’s tag I grabbed the PlayerController
component and checked if I really got one. Since I started the project faithfully with Unity 2018 (although I used the latest 2018.4), I discovered TryGetComponent()
doesn’t exist yet (got added with Unity 2019)…
This approach adds a dependency from CinematicTrigger
to RPG.Control
. I think this should be fine, though.
Thinking other cinematics might not be play once, I added a field for setting it.
using RPG.Control;
using UnityEngine;
using UnityEngine.Playables;
namespace RPG.Cinematics
{
public class CinematicTrigger : MonoBehaviour
{
[SerializeField] private bool isOnetimeTrigger = true;
private PlayableDirector director;
private void Awake()
{
director = GetComponent<PlayableDirector>();
}
private void OnTriggerEnter(Collider other)
{
// Debug.Log($"{name} was triggered by {other.name}");
// Only allow the player to trigger. Note: TryGetComponent() didn't exist yet in 2018.4
PlayerController player = other.GetComponent<PlayerController>();
if (null == player) return;
director.Play();
if (isOnetimeTrigger)
{
GetComponent<BoxCollider>().enabled = false;
}
}
}
}