Is there a way to pass parameters into Scene Events?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Basel
Posts: 17
Joined: Tue Jul 19, 2022 1:07 pm

Is there a way to pass parameters into Scene Events?

Post by Basel »

Currently I have a function to UpdateGameState(parameter).

Wasn't sure how to get this to show up is Scene Event. I'm just write specific functions that return void to get to work (e.g. UpdateCombatState(){UpdateGameState(CombatState);}

Is there another recommended way of doing this?

Thanks for your assistance.
User avatar
Tony Li
Posts: 21681
Joined: Thu Jul 18, 2013 1:27 pm

Re: Is there a way to pass parameters into Scene Events?

Post by Tony Li »

Hi,

Unity restricts UnityEvents such as the OnExecute() scene event to only accept primitive types or UnityEngine object types such as GameObject or Transform.

You could make those wrapper methods, or you could use a custom sequencer command instead of scene events. Example:

Code: Select all

// Syntax: UpdateGameState(state, subject)
// Example: UpdateGameState(combat, OrcBoss)
public class SequencerCommandUpdateGameState : SequencerCommand
{
    void Awake()
    {
        string state = GetParameter(0);
        AI ai = GetSubject(1).GetComponent<AI>();
        switch (GetParameter(0))
        {
            case "combat":
                ai.UpdateGameState(CombatState);
                break;
            case "idle":
                ai.UpdateGameState(IdleStatE);
                break;
        }
        Stop();
    }
}
There are many things you could do to enhance this script, such as checking if GetSubject(1) returns null, or -- if your game states are an enum -- use something like Enum.GetNames(typeof(GameState)) to get the game state names instead of hard-coding them here. The above is just a simple example.
Basel
Posts: 17
Joined: Tue Jul 19, 2022 1:07 pm

Re: Is there a way to pass parameters into Scene Events?

Post by Basel »

I really appreciate the breakdown, thank you.
It's one thing to make a great product, it's another thing to add great support to a great product. Many thanks for your time once again.
User avatar
Tony Li
Posts: 21681
Joined: Thu Jul 18, 2013 1:27 pm

Re: Is there a way to pass parameters into Scene Events?

Post by Tony Li »

Glad to help!
Post Reply