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

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #13483
    Renaud St-Hilaire
    Level 19
    Participant
    Helpful?
    Up
    0
    ::

    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!

    1

      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();
          }
      }
    #13484
    Terence
    Level 30
    Keymaster
    Helpful?
    Up
    0
    ::

    Renaud, can you bold the lines 55 and 68 in your code above?

    #13508
    Renaud St-Hilaire
    Level 19
    Participant
    Helpful?
    Up
    0
    ::

    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.

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

    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.

    #13517
    Renaud St-Hilaire
    Level 19
    Participant
    Helpful?
    Up
    0
    ::

    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();
          }
      }
    #13520
    Terence
    Level 30
    Keymaster
    Helpful?
    Up
    0
    ::

    Hi Renaud, it is likely that some of the slots in your InventoryManager are not assigned. Can you double check?

    InventoryManager slots not assigned

    The NullReferenceException is saying that your passiveItemUISlots[slotIndex] and weaponUISlots[slotIndex] variables are null, so you cannot do something like weaponUISlots[slotIndex].enabled, because it evaluates to null.enabled.

    #13521
    Renaud St-Hilaire
    Level 19
    Participant
    Helpful?
    Up
    0
    ::

    Nice its working now, I probably did something that made them unassigned because it was working fine at first. Thank you for the help!

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

Go to Login Page →


Advertisement below: