How to set a portrait at runtime?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
swampytable
Posts: 9
Joined: Sat Jun 27, 2020 6:07 pm

How to set a portrait at runtime?

Post by swampytable »

Hi,

I currently am in a position where I have several selectable characters at the start of my game, and of course each one has a different portrait. I am using an actor, "Player" and currently setting the name like this:

Code: Select all

DialogueLua.SetActorField("Player", "Display Name", playerName);
I also have a portrait loaded when the game loads,

Code: Select all

Sprite playerPortrait = Resources.Load<Sprite>("PlayerCharacters/player1/Player1_portrait");
I would like to assign this portrait to the actor, "Player" in a similar way. I have tried things like,

Code: Select all

Sprite playerPortrait = Resources.Load<Sprite>("PlayerCharacters/player1/Player1_portrait");
Sprite[] playerPortraits = new Sprite[1];
playerPortraits[0] = playerPortrait;

DialogueLua.SetActorField("Player", "Pictures", playerPortraits);


OR
...
DialogueLua.SetActorField("Player", "Player Portraits", playerPortraits);

...

and many iterations of this.

What I need to figure out is a way to set the actor's portrait at runtime. Is there a way?

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

Re: How to set a portrait at runtime?

Post by Tony Li »

Hi,

Use:

Code: Select all

DialogueLua.SetActorField("Player", "Current Portrait", "PlayerCharacters/player1/Player1_portrait");
Or use the SetPortrait() sequencer command.
swampytable
Posts: 9
Joined: Sat Jun 27, 2020 6:07 pm

Re: How to set a portrait at runtime?

Post by swampytable »

Hi Tony,

This works perfectly, thanks very much!
User avatar
Tony Li
Posts: 22093
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to set a portrait at runtime?

Post by Tony Li »

Glad to help!
Post Reply