Add Element to Sequence Accepted Tags in Code

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
n_hagialas
Posts: 36
Joined: Wed May 03, 2017 4:34 pm

Add Element to Sequence Accepted Tags in Code

Post by n_hagialas »

Hey Toni,

I'm trying to figure out how to add accepted tags elements via c# code. I've got the other components set properly but its just the accepted tags that I can't seem to get to work. It says the length is read only an adding a 1 to the first element for size isn't an option? It's 3 am maybe I'm missing something ><?
Q1. How do I set this array value? Like size to 1 and first element to Player.
Q2. Can I check if a trigger has a sequence trigger by comparing to null?

Code is below, error is towards the bottom. Code currently works only on the first element of the collection and then stops at the error. Thanks!

foreach (GameObject trigger in graveSceneTriggers)
{
if (trigger.GetComponent<SequenceTrigger>() == null) // if this trigger didnt retain its sequence trigger (Q2)
{
// Build new sequence trigger with proper number label
trigger.AddComponent<SequenceTrigger>();
SequenceTrigger ST = trigger.GetComponent<SequenceTrigger>();
ST.trigger = DialogueTriggerEvent.OnTriggerEnter;
ST.once = true;
ST.sequence = "AnimatorBool(GraveVinesGrow, true, GraveStory_Vines_0" + vineValue + ")@.2; \n" +
"AnimatorBool(GraveVinesWiggle, true, GraveStory_Vines_0" + vineValue + ")@1; \n" +
"AnimatorBool(GraveVinesGrow, false, GraveStory_Vines_0" + vineValue + ")@1.1;";
ST.condition.acceptedTags[0] = "Player"; // error is happening here (Q1)
}
vineValue++;
}
vineValue = 1;
User avatar
Tony Li
Posts: 22059
Joined: Thu Jul 18, 2013 1:27 pm

Re: Add Element to Sequence Accepted Tags in Code

Post by Tony Li »

Hi,

acceptedTags is an array of strings. Try this:

Code: Select all

ST.condition.acceptedTags = new string[] { "Player" };
n_hagialas
Posts: 36
Joined: Wed May 03, 2017 4:34 pm

Re: Add Element to Sequence Accepted Tags in Code

Post by n_hagialas »

I tried that exact line and even tried specifying a size and it didn't seem to fix the issue. I tried initializing on one line and then setting the value but it didn't work that way either. Here is the error from Unity:

NullReferenceException: Object reference not set to an instance of an object
GraveScenarioController.resetVineScenarioTriggers () (at Assets/Scripts/GraveScenarioController.cs:54)
UnityEngine.Component:SendMessage(String, Object, SendMessageOptions)
PixelCrushers.DialogueSystem.Sequencer:HandleSendMessageInternally(String, String[])
PixelCrushers.DialogueSystem.Sequencer:HandleCommandInternally(String, String[], Single&)
PixelCrushers.DialogueSystem.Sequencer:ActivateCommand(String, String, String[])
PixelCrushers.DialogueSystem.Sequencer:PlayCommand(QueuedSequencerCommand, String, Boolean, Single, String, String, String[])
PixelCrushers.DialogueSystem.Sequencer:PlayCommand(QueuedSequencerCommand)
PixelCrushers.DialogueSystem.Sequencer:PlaySequence(String)
PixelCrushers.DialogueSystem.Sequencer:PlaySequence(String, Boolean, Boolean)
PixelCrushers.DialogueSystem.Sequencer:PlaySequence(String, Transform, Transform, Boolean, Boolean)
PixelCrushers.DialogueSystem.DialogueSystemController:PlaySequence(String, Transform, Transform, Boolean, Boolean, String)
PixelCrushers.DialogueSystem.DialogueSystemController:PlaySequence(String, Transform, Transform, Boolean)
PixelCrushers.DialogueSystem.DialogueSystemController:PlaySequence(String, Transform, Transform)
PixelCrushers.DialogueSystem.DialogueManager:PlaySequence(String, Transform, Transform)
PixelCrushers.DialogueSystem.SequenceStarter:TryStartSequence(Transform, Transform)
PixelCrushers.DialogueSystem.SequenceTrigger:OnTriggerEnter2D(Collider2D)
User avatar
Tony Li
Posts: 22059
Joined: Thu Jul 18, 2013 1:27 pm

Re: Add Element to Sequence Accepted Tags in Code

Post by Tony Li »

Hi,

It looks like you just need to initialize ST.condition first. Here's an example. It adds a "Fade(out)" sequence to the GameObject that fires OnConversationEnd. The key is to add the line marked "THIS LINE" below.

AddSequenceTriggerTest.cs

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;

public class AddSequenceTriggerTest : MonoBehaviour
{
    void Start()
    {
        var trigger = this.gameObject;

        SequenceTrigger ST = trigger.AddComponent<SequenceTrigger>();
        ST.trigger = DialogueTriggerEvent.OnConversationEnd;
        ST.once = true;
        ST.sequence = "Fade(out,2)";
        ST.condition = new Condition(); //<--THIS LINE.
        ST.condition.acceptedTags = new string[] { "Player" };
    }
}
Post Reply