NeoFPS HitscanShooter null pointer effect hit

So this is weird but I have a null pointer error that I cannot find because it doesn’t appear to occur when using the debugger or when debug logging with if statements or anything.

It is in
NeoFPS\Core\Weapons\ModularFirearm\Shooters\HitscanShooter.cs
line 151

effect.Hit(m_Hit, newRayDirection, m_Hit.distance, float.PositiveInfinity, firearm as IDamageSource);

and/or 157

effect.Hit(m_Hit, ray.direction, m_Hit.distance, float.PositiveInfinity, firearm as IDamageSource);

I have checked the variables effect and all parameters passed multiple times now but none of them are null. Debug logging them never prints null and neither with a breakpoint. I am even able to break in the Hit function.

I am also able to get into the Hit function being executed and nothing appears to be null there either except for maybe collider, but commenting out the code doesn’t help. I already commented out the whole function contents and it keeps throwing the errors at lines 151/157

Even put a catch around it

catch (System.Exception e)
            {
                Debug.Log(effect);
                Debug.Log(hitPoint);
                Debug.Log(firearm);
            }

But it logs them just fine? huh?

Any other ways I could figure out what is going on because it appears as if nothing is null and there should not be an exception.

I can’t really see any way to break on exception (as you could with PHP for example)

If it’s happening on that line, would that imply that effect is what’s null?

Well you can see I logged it as the BulletAmmoEffect object at the top of the console in the image.

Only thing I can think of that something inside of the objects might be null. But then the error reporting on this line would be weird?

The only parameter that can be null is your IDamageSource interface, which could potentially happen if you cast an invalid type (using as casting results in a null if you try an invalid cast).

However, if one of the parameters happened to be null, the error would be pointing to the line where you try to access any of the null value’s properties. The error is pointing to the method call itself.

The only property you are accessing in the method call itself is m_hit.distance, which is a struct and can’t be null.

Thus only effect itself can be the source of the null reference error. So looking into the method is taking you on a wild goose chase and you probably want to look into why effect is null.

Ah nvm it was another script that was called through an event listener, not sure why the error wouldn’t just be displayed on that line when clicking it.

I noticed the error in the console (I didn’t show it here) had another script name in it than the script it showed me when clicking on it.