NullReferenceException for health script


What is the solution for this problem ?

1 Like

I’d say initialise connectionToClient. Hard to know for sure with what’s here. Maybe the connection has fallen out, but I’d guess the former.

That’s of course assuming you’re showing the script in question.

1 Like

I get the connectionId but when I check the connectionToclient.connectionId it is null.

1 Like

That wouldn’t generate that error, only if connectionToClient itself is null.

1 Like

I also tried this but it didn’t work.

1 Like

connectionId in this method is coming from the UnitBase, so you are saying that connection is not null?
connectionToClient.connectionId is the one from the health script, that is the on you are saying is null?

What version of Mirror and Unity are you using?
Does the gameObject with the health component throwing the error have a network identity component attached?

1 Like

fwiw, only connectionToClient can be null. connectionId (both the parameter, and the property) is an integer and cannot be null. It’s not possible unless they were declared as int? or Nullable<int>, and they weren’t. I checked.

2 Likes

Privacy & Terms