fungus
fungus copied to clipboard
PortraitController.Show tries to access a null portrait
When called, the method Show(Character character, string position) will create a new PortraitOptions variable with default values, and later will try to read the "portrait" property of this variable. Since the portrait is never properly set in this method, it will always error on the following two lines:
options.character.State.SetPortraitImageBySprite(options.portrait);
options.character.State.portraitImage.rectTransform.gameObject.SetActive(true);
Changing this Show method to require a string with the name of the portrait, and then setting the "portrait" property of the PortraitOptions variable fixes the issue. This is what the method looks like when fixed:
public virtual void Show(Character character, string portrait, string position)
{
PortraitOptions options = new PortraitOptions(true);
options.character = character;
options.portrait = character.GetPortrait(portrait);
options.fromPosition = options.toPosition = stage.GetPosition(position);
Show(options);
}
I thought about submitting a pull request, but I don't know if this method is used by something else, and didn't want to risk breaking someone else's project by changing the API
What you're trying to achieve exactly?
Getting specific portrait can be done with just character.State.portraitImage.name;
I'm trying to display a character at a certain position on the stage. The character was created properly (with a portrait), and I tried to use the Show method to make the character appear, but the way it is, the method tries to access an invalid portrait. I edited the Show method locally to make it set the portrait according to the character's default character, and it's working properly