call ChangeActorName in C#?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Raelyr
Posts: 19
Joined: Sat Aug 12, 2017 11:47 am

call ChangeActorName in C#?

Post by Raelyr »

Hey, I have the ChangeActorName script Tony suggested to set actors' display names during dialogue (ie if someone introduces themselves). Can I call that in C# as well?

Specifically, let's say I have an external save system, and I store the 'state' of the various characters the player has met. Now I want to see if each of those characters was properly introduced, and set their display names on load if so. I have this snippet of code:

Code: Select all

		foreach (string charac in characters) { // iterate over characters we've met
			if (characters[charac] != "encountered") { // if not just 'encountered', they are at least introduced
				ChangeActorNameLua.ChangeActorName(charac, charac); // so set it to their real name
			}
		}
However it returns an error because the ChangeActorNameLua script is public, but not public static. I considered just making it public static, but it necessarily includes the OnEnable and OnDisable methods which would also need to be set to public static. Would that interfere with anything? Like if another script has an OnEnable as well? Is there a better way to do this altogether?

For reference, here's the ChangeActorName stuff.
Raelyr
Posts: 19
Joined: Sat Aug 12, 2017 11:47 am

Re: call ChangeActorName in C#?

Post by Raelyr »

Welp, as usual, as soon as I posted I figured it out. Since I won't be loading any games with an ongoing conversation, I can just take the important line out of the ChangeActorName method anyway (DialogueLua.SetActorField(actorName, "Display Name", newDisplayName);).
User avatar
Tony Li
Posts: 21722
Joined: Thu Jul 18, 2013 1:27 pm

Re: call ChangeActorName in C#?

Post by Tony Li »

Hi,

If you need to change it during a conversation, you can do this:

Code: Select all

FindObjectOfType<ChangeActorNameLua>().ChangeActorName("Mephistopheles", "Mephistopheles");
It assumes you have added ChangeActorNameLua to the scene, such as on the Dialogue Manager.
Raelyr
Posts: 19
Joined: Sat Aug 12, 2017 11:47 am

Re: call ChangeActorName in C#?

Post by Raelyr »

Thanks! That's the answer I was originally looking for, I'll make a note in case there is a situation later where I need to save/load during a conversation. :)
Post Reply