Zombie Shooter - Null Exception - Basic Ammo Functionality

Using Unity 2023.1.9f1

I’m running into this weird problem where Unity is throwing ArgumentNullException: Value. The Game runs with no errors if I remove [SerializedField] Ammo ammoSlot;. Strangely enough the game runs fine after I unpause.

Here are some troubleshooting steps I’ve done:
• Remove [SerializedField] Ammo ammoSlot; (This removes error message)
• Reassign Player game object to Ammo Slot.
• Assigned ammoSlot = FindAnyObjectByType(); in Awake and Start methods along with Debug.Logs to double check.
• Debug.Logged void Shoot() and it works too.
• Added ammoSlot != null in if(ammoSlot.GetCurrentAmmo() >0) loop.

Since the game runs okay after I unpause, I’ll have to circle back because I really have no clue what’s going on here.

Can you share the full error message?

There was a lot of use error involved. The problem was that my Ammo script generated a bunch of packages when I tabbed to complete some lines of codes. I realized this part way through some other scripts. The game runs with no errors now when the packages were removed. Now it is just using the standard packages.

using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;

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

Privacy & Terms