Forum begins after the advertisement:


[Part 12] Empty Level Up Screen Causing Hard Lock + Some other trouble spots!

Home Forums Video Game Tutorial Series Creating a Rogue-like Shoot-em Up in Unity [Part 12] Empty Level Up Screen Causing Hard Lock + Some other trouble spots!

  • This topic has 16 replies, 5 voices, and was last updated 4 months ago by Sed.
Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
    Posts
  • #11824
    Stefano
    Silver Supporter (Patron)

    Hello! I absolutely love your series, and just finished Part 12 (I so can’t wait for the next part!), however, I am encountering a few issues, with one of them being the main topic of this post!

    Issue 1:

    After I have finished upgrading all of my weapons and passive items to their max levels, the next time I level up will display an empty Level Up screen, and I am unable to continue playing. I lose all functionality, and can’t close the window.

    Issue 2:

    Every time I exit play mode, I am met with this Null Reference Exception:

    “NullReferenceException: Object reference not set to an instance of an object
    EnemyStats.OnDestroy () (at Assets/Scripts/Enemy/EnemyStats.cs:70)”

    When I look at that particular code block, I’m not seeing anything different from what was suggested in the tutorial. Here is the script:

    private void OnDestroy()
    {
        EnemySpawner es = FindObjectOfType<EnemySpawner>();
        es.OnEnemyKilled();
    }

    Issue 3:

    If I choose the Garlic Character (I’ve named him AoE Master lol), and I proceed to play and collect the Knife and Spinach to create my Evolved Knife Weapon, my Garlic Weapon is removed from the primary slot, replaced by my Evolved Knife Weapon, and the Knife weapon that I collected (and was in the second slot) remained, and I was able to level it up. Also, I was able to recollect the Garlic Weapon, but it was always listed as Level 4, and it took up an inventory slot each time I selected it.

    Related to inventory slots, each time I’ve reached 5 inventory slots (Elements 0-4 filled), I will receive the “All slots full” message in the console, and I am also unable to continue and exit the Level Up screen. Element 5 is empty when I view the Player Inventory in the Inspector. I have no idea if all of these are related to the issue of multiple instances of a Weapon or Passive appearing in the Level Up screen (I also saw that with a Health Upgrade Item I created that otherwise worked perfectly until it was maxed out).

    Any help would be greatly appreciated! Thank you for this wonderful series, and for your time!

    #11840
    Terence
    Keymaster

    Hi Stefano, Xavier (our series creator) is on a break over the weekend. In the interim, let me chime in with a fix for the NullReferenceException issue you are running to. You can do the following to fix it:

    private void OnDestroy()
    {
        EnemySpawner es = FindObjectOfType<EnemySpawner>();
        if(es) es.OnEnemyKilled();
    }

    The exception is firing because the FindObjectOfType() method is unable to find an EnemySpawner (it’s probably destroyed first, before your EnemyStats script, when you exit. Hence, the line you highlighted becomes null.OnEnemyKilled(), which causes a NullReferenceException.

    We’ve made a video documenting what NullReferenceException errors are and how to fix them:

    #11846
    Xavier Lee
    Keymaster

    Hi Stefano, those are some interesting errors.

    Issue 1:

    This problem happens because we are applying the upgrade options every time the player levels up. That means when the player has completely maxed out all of their weapons and passive items, the Level Up Screen will still show. And if you remember, the only way to close the Level Up Screen is to select an upgrade.

    Issue 2:

    This problem is a relatively simple one. You can find the answer to this here.

    Issue 3:

    That’s a weird problem. Could you provide more context to your set up and perhaps consider sending a video?

    #11856
    Stefano
    Silver Supporter (Patron)

    Thank you so much for your response!

    I was able to address issue 2 thanks to your advice! Thank you! The video you linked to was also super helpful!

    As for Issue 1, in Vampire Survivor, when the player has maxed out all available options, they are then presented with two choices: collect coins, or collect a healing meat. I’d like to implement a similar function, but I’m unsure of how to do that! I believe that would resolve the issue, and allow the player to keep playing the game even when they Level Up. Is there any way you can help me out there?

    I’m actually not seeing the duplicate weapon/passive item issue anymore. I might have had their index numbers mislabeled.

    I can post a video of the Level Up screen issue I’m seeing, however. I’ve also noticed that sometimes, Gems will fly past the character when moving quickly, instead of being collected. The video I’m sharing has that in it as well! Thank you again for all of your help! Here is the video:

    Level Up bug video

    #11859
    Terence
    Keymaster

    Hi Stefano,

    If I recall correctly, the gems are moved using a Rigidbody correct? If you set the Rigidbody’s Collision Detection attribute to Continuous, it should fix the gem tunnelling through the player.

    #11860
    Stefano
    Participant

    Ah, interesting! I’ll give that a shot! Thank you!

    #11861
    Stefano
    Silver Supporter (Patron)

    Unfortunately, the gems are still flying past the player, even with the Collision Detection turned to Continuous. I tried increasing the radius of the pick up object, but that didn’t work either :(

    #11862
    Terence
    Keymaster

    What if you made the player use Continuous collision as well?

    #11865
    Stefano
    Silver Supporter (Patron)

    Yeah, I tried that as well, and it didn’t work either, sadly! It seems like the gem only accounts for the initial magnet pull towards the player, but if the gem misses the player completely (which happens often when dodging incoming targets, it won’t reverse course and pull towards the player again, even if the player tries to chase the gem. If they’re fast enough (like with a high move speed), they can chase the gem down and collect it, but if they’re too slow, the gem just keeps flying off in the direction it was pulled

    #11867
    Xavier Lee
    Keymaster

    Hi Stefano, this problem occurs when the player is faster than the pulling animation. You can try increasing the pull speed to account for your player’s increase in speed as well.

    Another way to do it is to simply make the item follow the player’s location. To do this, you would need to add functionality in a script (Perhaps the PlayerCollector script or you could create your own). Inside of this script, you can make use of the Vector3.MoveTowards() function in Update() to make the item track the player. The reason I didn’t make use of such a method in the Tutorial Series is because it gets very computationally intensive, especially when there are a lot of items. If you recall, the pull is mainly an animation used to give feedback to the player that they have collected an item.

    Hope this helps!

    #11869
    Stefano
    Silver Supporter (Patron)

    Xavier, thank you so much for the advice! I will look into this and give it a try!

    Is there a way you could help me sort out the Level Up issue I’m seeing? I’ve been banging my head against the wall for a few days now trying to solve it! As mentioned above, when the player has maxed out all available upgrades for their weapons and passive items, an empty Level Up screen will appear that cannot be closed. One of the solutions I was thinking of was similar to Vampire Survivors, where the player will be given a choice between receiving gold, or receiving a health replenishment. Unfortunately, I have been unable to implement this! I’ve done a bunch of trial and error with the code, but I can’t seem to get the code to function!

    I’ve mostly been working in the Inventory Manager script, since that is where the Level Up and Upgrade options functions are at, but the closest I’ve been able to get is a debug.log message to appear, but it’s not appearing when I’d like (when all available weapon and passive item upgrades are maxed out). This Level Up issue is the main thing that is preventing me from continuing forward with this project, so it’s been really frustrating, to say the least!

    I appreciate you and Terance taking the time to assist me thus far! Thank you so much!

    #11871
    Terence
    Keymaster

    Hi Stefano,

    The Level Up issue is a bit dicey, because there is quite a lot of room for improvement in the way that it is coded, and there is no easy way to hack in the functionality that you want. We’ll have to restructure the code quite a bit to get that one in, and it is something that we have planned in future.

    In the meantime, what you can do is add a Level Cap to the PlayerStats script, like so, and prevent the ability to gain experience when the player hits the level cap:

    public class PlayerStats : MonoBehaviour {
        ...
        public int levelCap = 9;
        ...
        public void IncreaseExperience(int amount) {
            if(level >= levelCap) return;
    
            experience += amount;
            LevelUpChecker();
            UpdateExpBar();
        }
    }

    Hope this makes sense!

    #11872
    Stefano
    Participant

    Thank you so much! The level up cap at the very least helps unblock me for now! Sometimes the blank level up screen will still pop up (even if not all weapons/passive items have been maxed out), but it’s significantly better than before, and I can work on other aspects in the meantime (such as trying to get the knockback function I’ve implemented working fully; so far I can knock enemies back, but if they are hit from the left, they will fly towards the player, instead of away. If they are hit from the right, they fly away from the player as intended, however!)

    Thank you again for your patience in helping me sort out these issues! I’m really looking forward to future entries in the series! Wishing you all the best!

    #11873
    Terence
    Keymaster

    No problem Stefano. Just putting it out there, but if there are any features you’ll like to develop on top of our tutorials, we also offer coaching services where we:

    1. Help you to fully scope out your additional feature(s).
    2. Develop the necessary scripts / resources for you for your feature.
    3. Do a video call with you to run through the newly-developed codes with you.
    #11876
    Stefano
    Participant

    I would absolutely be interested in some coaching services!

    I’m currently building out a prototype for a project like this, which is how I stumbled across your series, and it’s been incredibly informative and insightful, but I’d love to learn more! I work in the gaming industry as a game designer, but I don’t do programming! 😂

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

Go to Login Page →


Advertisement below: