Page 1 of 1

call ChangeActorName in C#?

Posted: Tue Oct 15, 2019 10:27 am
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.

Re: call ChangeActorName in C#?

Posted: Tue Oct 15, 2019 10:34 am
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);).

Re: call ChangeActorName in C#?

Posted: Tue Oct 15, 2019 11:19 am
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.

Re: call ChangeActorName in C#?

Posted: Tue Oct 15, 2019 1:14 pm
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. :)