Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PortraitController.Show tries to access a null portrait #1041

Open
vitormaduro opened this issue Nov 24, 2021 · 2 comments
Open

PortraitController.Show tries to access a null portrait #1041

vitormaduro opened this issue Nov 24, 2021 · 2 comments
Labels
bug Doing something it's not meant to, or not doing something it's meant to.

Comments

@vitormaduro
Copy link

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

@vitormaduro vitormaduro added the bug Doing something it's not meant to, or not doing something it's meant to. label Nov 24, 2021
@breadnone
Copy link
Contributor

breadnone commented Nov 24, 2021

What you're trying to achieve exactly?

Getting specific portrait can be done with just character.State.portraitImage.name;

@vitormaduro
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Doing something it's not meant to, or not doing something it's meant to.
Projects
None yet
Development

No branches or pull requests

2 participants