Change Actor Portrait from script

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
makovetksyi
Posts: 13
Joined: Fri Sep 22, 2023 7:35 pm

Change Actor Portrait from script

Post by makovetksyi »

Hi guys,

I want to change Actor portrait from script:

string actorName = "Hero";
Sprite newPortrait = AvaStandard;
Actor actor = DialogueManager.MasterDatabase.GetActor(actorName);
if (actor != null)
{
//actor.Name = _saveLoadService.CurrentSave.HeroStats.Character.Name;
DialogueLua.SetActorField(actorName, "Display Name", name);
actor.AssignPortraitSprite(newPortrait);
}

And get this error:
Assets/24/Global/Scripts/Hero/HeroController.cs(70,40): error CS1503: Argument 1: cannot convert from 'UnityEngine.Sprite' to 'PixelCrushers.DialogueSystem.Actor.AssignSpriteDelegate'


Any advice?
User avatar
Tony Li
Posts: 21679
Joined: Thu Jul 18, 2013 1:27 pm

Re: Change Actor Portrait from script

Post by Tony Li »

Hi,

Actor.AssignPortraitSprite() has a different purpose.

Just assign Actor.spritePortrait:

Code: Select all

actor.spritePortrait= newPortrait;
Note: If the Dialogue Manager's Other Settings > Instantiate Database is UNticked, this will change your dialogue database asset when in play mode. If Instantiate Database is unticked, instead add a Dialogue Actor component to the actor's GameObject. Set the actor and spritePortrait. Example:

Code: Select all

dialogueActor.actor = actor.Name;
dialogueActor.spritePortrait = newPortrait;
makovetksyi
Posts: 13
Joined: Fri Sep 22, 2023 7:35 pm

Re: Change Actor Portrait from script

Post by makovetksyi »

error CS0103: The name 'dialogueActor' does not exist in the current context

What should I use additionally to using PixelCrushers.DialogueSystem;?
User avatar
Tony Li
Posts: 21679
Joined: Thu Jul 18, 2013 1:27 pm

Re: Change Actor Portrait from script

Post by Tony Li »

Hi,

That code assumes that you've added a Dialogue Actor component to the GameObject, and that 'dialogueActor' is a reference to that component, such as: var dialogueActor = yourGameObject.GetComponent<DialogueActor>();

What about just using actor.spritePortrait = newPortrait? This doesn't require a Dialogue Actor component. Can you do that, or did you untick the Dialogue Manager's Instantiate Database checkbox?
makovetksyi
Posts: 13
Joined: Fri Sep 22, 2023 7:35 pm

Re: Change Actor Portrait from script

Post by makovetksyi »

Tony Li wrote: Sat Sep 23, 2023 2:51 pm Hi,

That code assumes that you've added a Dialogue Actor component to the GameObject, and that 'dialogueActor' is a reference to that component, such as: var dialogueActor = yourGameObject.GetComponent<DialogueActor>();

What about just using actor.spritePortrait = newPortrait? This doesn't require a Dialogue Actor component. Can you do that, or did you untick the Dialogue Manager's Instantiate Database checkbox?
Thanks - it helped!
User avatar
Tony Li
Posts: 21679
Joined: Thu Jul 18, 2013 1:27 pm

Re: Change Actor Portrait from script

Post by Tony Li »

Glad to help!
Post Reply