Forum begins after the advertisement:
[Part 10] Upgrade Menu Stays active after choosing upgrade
Home › Forums › Video Game Tutorial Series › Creating a Rogue-like Shoot-em Up in Unity › [Part 10] Upgrade Menu Stays active after choosing upgrade
- This topic has 6 replies, 2 voices, and was last updated 8 months, 2 weeks ago by Renaud St-Hilaire.
-
AuthorPosts
-
March 7, 2024 at 7:10 am #13483::
Hi, I get a nullreferenceException error when choosing an upgrade, the adding weapons/leveling up works but the panel doesnt disappear after choosing. Here’s a screenshot of both the Game manager and the inventory manager and the AddPassive and AddWeapon code. Thanks for the help!
public void AddWeapon(int slotIndex, WeaponController weapon) //Add a weapon to a specific slot { weaponSlots[slotIndex] = weapon; weaponLevels[slotIndex] = weapon.weaponData.Level; weaponUISlots[slotIndex].enabled = true; //Enable the image component weaponUISlots[slotIndex].sprite = weapon.weaponData.Icon; if (GameManager.instance != null && GameManager.instance.choosingUpgrade) { GameManager.instance.EndLevelUp(); } } public void AddPassiveItem(int slotIndex, PassiveItem passiveItem) //Add a passive item to a specific slot { passiveItemSlots[slotIndex] = passiveItem; passiveItemLevels[slotIndex] = passiveItem.passiveItemData.Level; passiveItemUISlots[slotIndex].enabled = true; //Enable the image component passiveItemUISlots[slotIndex].sprite = passiveItem.passiveItemData.Icon; if (GameManager.instance != null && GameManager.instance.choosingUpgrade) { GameManager.instance.EndLevelUp(); } }
March 7, 2024 at 8:30 pm #13484March 9, 2024 at 10:51 pm #13508::Im not sure what do you mean by bold the lines, you mean make them bold? or like make them unactive with a double slash // ? Im sorry for my english its not my first language.
March 9, 2024 at 11:30 pm #13509::Renaud, that’s right, I mean to make them bold. I suspect your issues have to do with the errors that are appearing, but I need to know which lines are being referred to so I can help you fix them.
March 10, 2024 at 3:08 am #13517::Ok! Its the two lines that enables the image components.
public void AddWeapon(int slotIndex, WeaponController weapon) //Add a weapon to a specific slot { weaponSlots[slotIndex] = weapon; weaponLevels[slotIndex] = weapon.weaponData.Level; weaponUISlots[slotIndex].enabled = true; //Enable the image component weaponUISlots[slotIndex].sprite = weapon.weaponData.Icon; if (GameManager.instance != null && GameManager.instance.choosingUpgrade) { GameManager.instance.EndLevelUp(); } }
public void AddPassiveItem(int slotIndex, PassiveItem passiveItem) //Add a passive item to a specific slot { passiveItemSlots[slotIndex] = passiveItem; passiveItemLevels[slotIndex] = passiveItem.passiveItemData.Level; passiveItemUISlots[slotIndex].enabled = true; //Enable the image component passiveItemUISlots[slotIndex].sprite = passiveItem.passiveItemData.Icon; if (GameManager.instance != null && GameManager.instance.choosingUpgrade) { GameManager.instance.EndLevelUp(); } }
March 10, 2024 at 7:09 pm #13520::Hi Renaud, it is likely that some of the slots in your InventoryManager are not assigned. Can you double check?
The NullReferenceException is saying that your
passiveItemUISlots[slotIndex]
andweaponUISlots[slotIndex]
variables are null, so you cannot do something likeweaponUISlots[slotIndex].enabled
, because it evaluates tonull.enabled
.March 10, 2024 at 10:31 pm #13521::Nice its working now, I probably did something that made them unassigned because it was working fine at first. Thank you for the help!
-
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: