Page 1 of 1

Change Actor Portrait from script

Posted: Fri Sep 22, 2023 7:37 pm
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?

Re: Change Actor Portrait from script

Posted: Fri Sep 22, 2023 8:39 pm
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;

Re: Change Actor Portrait from script

Posted: Sat Sep 23, 2023 1:00 pm
by makovetksyi
error CS0103: The name 'dialogueActor' does not exist in the current context

What should I use additionally to using PixelCrushers.DialogueSystem;?

Re: Change Actor Portrait from script

Posted: Sat Sep 23, 2023 2:51 pm
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?

Re: Change Actor Portrait from script

Posted: Thu Sep 28, 2023 9:56 am
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!

Re: Change Actor Portrait from script

Posted: Thu Sep 28, 2023 10:17 am
by Tony Li
Glad to help!