Forum begins after the advertisement:


[Part 19] Some problems with generating the Upgrades after the changes

Home Forums Video Game Tutorial Series Creating a Rogue-like Shoot-em Up in Unity [Part 19] Some problems with generating the Upgrades after the changes

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #14395
    SameFate
    Level 1
    Participant
    Helpful?
    Up
    0
    ::

    Hey, I just worked through the newest part and got some problems at the end. When I get a level up the game throws a Null Reference Exception from this line in the GameManager:

        playerObject.SendMessage("RemoveAndApplyUpgrades");

    While ingame I only get the one premade button with its standard text and I cant click on the button. I configured the codes like said in the article. I also renamed the hierarchy of the upgrade button to make sure it is not the path of the objects that are to be filled. It seems like it does not modify the buttons correctly but I am not so sure… Are there any really important things I have to do while changing the codes or the overlay that is not described in the article?

    #14438
    Terence
    Level 30
    Keymaster
    Helpful?
    Up
    0
    ::

    SameFate, thanks for flagging this. There are some mistakes with the Part 19 article that I’ll be addressing in the stream tomorrow. I’ll also be adding some new features.

    Kok Tong has helped me check through the part today and he found a few issues. I hope this helps in the meantime:

    I’ve tested out part 19, and here’s what I found:

    a few errors after implementing section 4:

    1. PlayerInventory
    • cannot implicity convert type “Item.LevelData” to “Weapon.Stats”
    • on line 358 and 365:
            Weapon.Stats nextLevel = ((WeaponData)chosenUpgrade).GetLevelData(item.currentLevel + 1);
            Passive.Modifier nextLevel = ((PassiveData)chosenUpgrade).GetLevelData(item.currentLevel + 1);
    1. Weapon
    • “Stats” is defined twice:
              public struct Stats 
              public class Stats : LevelData
    1. “name” and “description” are serialized twice in Weapon and Passive scripts

    section 5:

    1. In section 2, I checked the height boxes of “Control Child Size” and “Child Force Expand”, when I deleted the rest of the upgrade options in section 5, the 1 leftover upgrade option scaled up to cover the entire frame. (fixed this by unchecking the height boxes)

    What happens when there are no more weapons left:

    1. Once I level up a weapon to its max level, I get options beyond its max level. For example, a level 6 duplicator (max level is 5).

    2. After I fill up all weapon slots, I still get the option for new weapons.

    ^^ Selecting them does nothing, so I’m stuck at the level-up screen.

    #14446
    Terence
    Level 30
    Keymaster
    Helpful?
    Up
    0
    ::

    Made some changes to the article for Part 19. There was a Luck formula bug in the PlayerInventory.cs that caused the 4th upgrade to always spawn, and we assigned allPossibleUpgrades instead of availableUpgrades to the 4-upgrade spawn, which means that it was possible to still receive upgrades when our weapon / passive slots were full.

    bool getExtraItem = 1f - 1f / player.Stats.luck <> UnityEngine.Random.value;
    if(getExtraItem) upgradeWindow.SetUpgrades(this, allPossibleUpgradesavailableUpgrades, 4);
    else upgradeWindow.SetUpgrades(this, availableUpgrades, 3, "Increase your Luck stat for a chance to get 4 items!");
    #14447
    Terence
    Level 30
    Keymaster
    Helpful?
    Up
    1
    ::

    There was also an issue with the SetUpgrades() function in the UIUpgradeWindow script which made it so that it will always show 4 upgrades after showing 4 upgrades for the first time. This was caused by a missing condition in the loop that showed the upgrade options (highlighted below).

    Here are the changes:

    public void SetUpgrades(PlayerInventory inventory, List<ItemData> possibleUpgrades, int pick = 3, string tooltip = "") 
    {
        pick = Mathf.Min(maxOptions, pick);
    
        // If we don't have enough upgrade option boxes, create them.
        if (maxOptions > upgradeOptions.Count)
        {
            for (int i = upgradeOptions.Count; i < pick; i++)
            {
                GameObject go = Instantiate(upgradeOptionTemplate.gameObject, transform);
                upgradeOptions.Add((RectTransform)go.transform);
            }
        }
    
        // Update the tooltip and turn it off if it is empty.
        tooltipTemplate.text = tooltip;
        tooltipTemplate.gameObject.SetActive(tooltip.Trim() != "");
    
        // Activate only the number of upgrade options we need, and arm the buttons and the
        // different attributes like descriptions, etc.
        activeOptions = 0;
        int totalPossibleUpgrades = possibleUpgrades.Count; // How many upgrades do we have to choose from?
        foreach(RectTransform r in upgradeOptions)
        {
            if (activeOptions < pick && activeOptions < totalPossibleUpgrades)
            {
                r.gameObject.SetActive(true);
    
                // Select one of the possible upgrades, then remove it from the list.
                ItemData selected = possibleUpgrades[Random.Range(0, possibleUpgrades.Count)];
                possibleUpgrades.Remove(selected);
                Item item = inventory.Get(selected);
    
                // Insert the name of the item.
                TextMeshProUGUI name = r.Find(namePath).GetComponent<TextMeshProUGUI>();
                if(name)
                {
                    name.text = selected.name;
                    if(item)
                    {
                        name.text += " - Level " + (item.currentLevel + 1);
                    }
                }
    
                // Insert the description of the item.
                TextMeshProUGUI desc = r.Find(descriptionPath).GetComponent<TextMeshProUGUI>();
                if (desc)
                {
                    if (item)
                    {
                        desc.text = selected.GetLevelData(item.currentLevel + 1).description;
                    }
                    else
                    {
                        desc.text = selected.GetLevelData(1).description;
                    }
                }
    
                // Insert the icon of the item.
                Image icon = r.Find(iconPath).GetComponent<Image>();
                if(icon)
                {
                    icon.sprite = selected.icon;
                }
    
                // Insert the button action binding.
                Button b = r.Find(buttonPath).GetComponent<Button>();
                if (b)
                {
                    b.onClick.RemoveAllListeners();
                    if (item)
                        b.onClick.AddListener(() => inventory.LevelUp(item));
                    else
                        b.onClick.AddListener(() => inventory.Add(selected));
                }
    
                activeOptions++;
            }
            else r.gameObject.SetActive(false);
        }
    }
    has upvoted this post.
    #14449
    Terence
    Level 30
    Keymaster
    Helpful?
    Up
    0
    ::
    Made some changes to the article for Part 19. There was a Luck formula bug in the PlayerInventory.cs that caused the 4th upgrade to always spawn, and we assigned allPossibleUpgrades instead of availableUpgrades to the 4-upgrade spawn, which means that it was possible to still receive upgrades when our weapon / passive slots were full.
    bool getExtraItem = 1f - 1f / player.Stats.luck <> UnityEngine.Random.value;
    if(getExtraItem) upgradeWindow.SetUpgrades(this, allPossibleUpgradesavailableUpgrades, 4);
    else upgradeWindow.SetUpgrades(this, availableUpgrades, 3, "Increase your Luck stat for a chance to get 4 items!");

    Had another issue for this part as well, where the level up window still showed up when we ran out of upgrades. To prevent this from happening, we need to do a check and stop the level up when there are no more possible upgrades:

    int availUpgradeCount = availableUpgrades.Count;
    if (availUpgradeCount > 0)
    {
        bool getExtraItem = 1f - 1f / player.Stats.luck > UnityEngine.Random.value;
        if(getExtraItem) upgradeWindow.SetUpgrades(this, availableUpgrades, 4);
        else upgradeWindow.SetUpgrades(this, availableUpgrades, 3, "Increase your Luck stat for a chance to get 4 items!");
    }
    else if(GameManager.instance != null && GameManager.instance.choosingUpgrade)
    {
        GameManager.instance.EndLevelUp();
    }
    #14462
    Terence
    Level 30
    Keymaster
    Helpful?
    Up
    0
    ::
    Hey, I just worked through the newest part and got some problems at the end. When I get a level up the game throws a Null Reference Exception from this line in the GameManager:
        playerObject.SendMessage("RemoveAndApplyUpgrades");

    While ingame I only get the one premade button with its standard text and I cant click on the button. I configured the codes like said in the article. I also renamed the hierarchy of the upgrade button to make sure it is not the path of the objects that are to be filled. It seems like it does not modify the buttons correctly but I am not so sure… Are there any really important things I have to do while changing the codes or the overlay that is not described in the article?

    Hi SameFate, I’ve updated the Part 19 article with the fixes I’ve noted above. Hope it helps!

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: