Triggers

Announcements, support questions, and discussion for Quest Machine.
Post Reply
vectorfrog
Posts: 86
Joined: Mon May 02, 2022 12:16 am

Triggers

Post by vectorfrog »

Hello,

I am using the Opsive character controller and trying to use a trigger for a quest. I have a simple game object set up with a sphere collider component configured to be a trigger. I want this trigger to increase the counter of a quest but the trigger isn't sending the message. This game object has the Trigger Event component, and Quest Control component also.

Does the Quest Control component need to be configured in a specific way for the quest?

I can see when my character enters the trigger, as I have a log statement for that in OnTriggerEnter.

I have even tried to set up the start dialog with player trigger and that doesn't work either. Am I missing something because of using the opsive controller? Do the game object triggers need to be on a specific layer? The character object does have the correct tag of Player.
Screen Shot 2022-05-01 at 9.56.18 PM.png
Screen Shot 2022-05-01 at 9.56.18 PM.png (47.61 KiB) Viewed 1302 times
User avatar
Tony Li
Posts: 20769
Joined: Thu Jul 18, 2013 1:27 pm

Re: Triggers

Post by Tony Li »

Hi,

Your Trigger Event component's Tag Mask is set to Player. This means only GameObjects tagged Player will trigger it.

For Opsive characters, the collider is on a child GameObject that's untagged by default. You can tag this child GameObject as Player, or you can create a new tag, set the child to that tag, and also set the Trigger Event component's Tag Mask to include that tag.
vectorfrog
Posts: 86
Joined: Mon May 02, 2022 12:16 am

Re: Triggers

Post by vectorfrog »

Thanks Tony! That was the problem. Wasn't even thinking of the actual character collider tag and didn't realize the stock OnTriggerEnter doesn't need a tag for triggering the event.
User avatar
Tony Li
Posts: 20769
Joined: Thu Jul 18, 2013 1:27 pm

Re: Triggers

Post by Tony Li »

Happy to help!
vectorfrog
Posts: 86
Joined: Mon May 02, 2022 12:16 am

Re: Triggers

Post by vectorfrog »

Hi Tony,

Well, I've run into a problem with this. The Opsive character controller has an option to initialize the character on awake. I am using this method as I have a character selection scene that instantiates my character, and then loads the game scene. The game scene finds the player based off of the Player tag. For some reason, it's finding the Player tag on the Capsule collider before the main game object and is failing to initialize the character and camera, therefore breaking my product all together.

Here is the strange part: It only does this when I do a stand alone build. Everything works fine if I run it in the editor. Have you seen this before? Is there a way to tell Quest Machine to use a different tag for the triggers? and other things? I'm still looking at the code but I wanted to see if you have any insight.

Thanks!
User avatar
Tony Li
Posts: 20769
Joined: Thu Jul 18, 2013 1:27 pm

Re: Triggers

Post by Tony Li »

Hi,

QuestGiver.StartDialogueWithPlayer() will find the QuestJournal() component anywhere. It doesn't technically need to be on a GameObject tagged "Player".

If the issue is with the Trigger Event component, here are two options:

1. Tag your the child collider object differently, maybe a new tag named "PlayerCollider" or something. Then add that tag to your Trigger Event's Tag Mask.

2. Or use Opsive's interaction system instead, like the integration's example scene. This is probably the better approach.
vectorfrog
Posts: 86
Joined: Mon May 02, 2022 12:16 am

Re: Triggers

Post by vectorfrog »

Thank you very much for the quick reply. I went with Option 1. I am using the interaction ability also for other things as well. But the triggers needed to work also. Thanks Tony!

I'm still very curious as to why this only happens on a build and not in the editor.
User avatar
Tony Li
Posts: 20769
Joined: Thu Jul 18, 2013 1:27 pm

Re: Triggers

Post by Tony Li »

It's probably just the order in which Unity returns GameObjects when UCC asks for GameObject.FindObjectWithTag("Player"). If there's more than one object tagged "Player", Unity doesn't guarantee which one it will return, and it could very well be different in builds vs. editor. It's similar to how multiple scripts can have a Start() method that runs when the scene starts, but Unity doesn't guarantee the order in which each Start() method runs.
Post Reply