Reward Text not showing up correctly with using GetDisplayName

After setting up the reward text system and testing. I seem to only be getting the number value of the rewards for completing quests. The names are not displayed at all. I was testing and I found that it does work if I use
rewardText += reward.item.name;
But using
rewardText += reward.item.GetDisplayName();
Then the item name does not show up. I am wondering why that is.
I have tried looking to find where the GetDisplayName is used to see if there is something missing but I am not sure. All I see is that GetDisplayName() is used with the InventoryItem script from GameDev. It is initialized to null and then referenced under a getter and returns the string displayName.

I do not know if the difference is by the version of Unity I have 2021.3.7f1 or if there is a break in the code that I am not noticing. But by using reward.item.name I seem to get the result as you do with using reward.item.GetDisplayName().

If you have any thoughts on why this is happening I am open to hearing about it.

Code Review:
``
private string GetRewardText(Quest quest)

    {

        string rewardText = "";

        foreach (var reward in quest.GetRewards())

        {

            if (rewardText != "")

            {

                rewardText += ", ";

            }

            if (reward.number > 1)

            {

                rewardText += reward.number + " ";

            }
            // Using rewardText += reward.item.name; does work for this for some reason.
            rewardText += reward.item.GetDisplayName();

        }

        if (rewardText == "")

        {

            rewardText = "No Reward";

        }

        rewardText += ".";

        return rewardText;

    }

``

I found my problem. I double checked the weapons and items for the rewards and the display name for them are empty. Everything is working correctly.

1 Like

Good catch. These sorts of errors can actually be difficult to track down, as the code is fine, but the inspector values aren’t.

1 Like

Thank You :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms