Any help?

I seem to have broken something. I just finished the “Patrolling Behavior” section under the Unity RPG Core Combat Creator: Learn Intermediate C# Coding course. And my guy (player model) and the Enemies are now gliding around. The enemies are using the waypoint paths the section showed me how to input, but I’m at a loss as to why my player and the enemy models broke their movement (walking behavior) . I receive this error over and over again for all people in the scene.


And when I click on it I get this are the bottom of the errors

In the code for the Mover.cs script that it’s pointing to… Line 23 isn’t showing me any errors. And I don’t think we even touched that in the section.

Can anyone guide me to what I did wrong? Or point me in the right direction?

Thank you in advance for reading this, and with any help/guidance you can provide.
Cheers.

Is there a navmeshAgent on the player gameobject? Is there a health component on that same gameobject? Double check your scene game object that these scripts are on.

Thankyou @Aionlasting. I Checked and yes. Everyone has a Nav Mesh Agent, and everyone has a Health component, with the Health.cs script attached.
I also looked at the Mover Script again as it is attached to the player and enemies as well, and it’s target field was blank. So I re-associated the models to the target fields for everyone, but that didn’t fix the issue. :frowning: But that also didn’t fix the issue.


Thank you so much for your help. Is there anything else that I might try?

@Aionlasting got it working.


At 9:26 in the video “Disable Control When Dead” under the Enemy AI section. Sam Pattuzzi says he is going to skip over taking a reference here again (Pointing at the “Health health;” in line 14). This adds the line 19 code (in the red box). I missed that step because I didn’t understand how he did that, and didn’t notice it “added” a line of code. I just added the line of code because I couldn’t figure out how to add that reference. Saved the script, and now it works.

Thank you so much for getting back to me Aionlasting.
Cheers Mate. :rainbow: :star:

Going forward with the RPG series, there will be times when we don’t explicitly mention caching a component reference with GetComponent<T>(). It’s safe to assume that if the component exists on the same GameObject as the script, and it’s not a [SerializeField] member, that it will need to be cached in Awake() or Start(). I usually recommend doing this in Awake() if the component exists on the same GameObject to help fight against race conditions.

1 Like

Thanks for getting back to me again @Brian_Trotter. Really appreciate the help, and this explanation here is very helpful going forward.

Cheers.

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

Privacy & Terms