NullReferenceException: Object reference not set to an instance of an object

Sorry about the wait, Yuri, I had to go to work.

As it turns out, there were still two issues outstanding with the code. Both of these were in PlayerController.cs, and are easy to miss at first glance.

The first thing I noticed was within the InteractWithCombat method… you have a line

if( target = null) continue;

This is an assignment rather than a comparison, so regardless of the status of target, it will be assigned to null within the if statement. (This is actually a common typo, but still hard to spot sometimes). The correct syntax is

if(target==null) continue;

So I fixed that in the code and it was still misbehaving, and not giving any logs to demonstrate that it ever was even entering InteractWithCombat… that’s when I went back to the Update Method… your code has InteractWithMovement before InteractWithCombat…
Unless the cursor is completely outside of the terrain, InteractWithCombat will always return true, so it needs to be the last if statement in your Update() method, not the first. Swap the order, so that InteractWithCombat is first, and everything should be right as rain.

1 Like

OMG THANK YOU SO MUCH ! I really appreciate your help brian your the best :smiley:

I’m glad to help.

1 Like

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

Privacy & Terms