Error When Trying To Implement The Source Code

Hi

Hi I get the following error when trying to implement the script of Unity 3rd Person Combat and Traversal.

NullReferenceException: Object reference not set to an instance of an object
PlayerBaseState.Move (UnityEngine.Vector3 motion, System.Single deltaTime) (at Assets/Scripts/State Machines/Player/PlayerBaseState.cs:21)
PlayerFreeLookState.Tick (System.Single deltaTime) (at Assets/Scripts/State Machines/Player/PlayerFreeLookState.cs:48)
StateMachine.Update () (at Assets/Scripts/State Machines/StateMachine.cs:18)

And the character don’t move. What will be the problem?

Thank you,

Ari

Something is null. Check PlayerBaseState on line 21. This is where something is null. Make sure it is not null

1 Like

Let’s start with a look at PlayerBaseState(), on line 21, something is null, in the Move() method. Paste in your PlayerBaseState() script (text, not screenshot, please), and we’ll take a look.

1 Like

Thank you for your help!

I figured out the problem. To be specific, it was because of some fields on the PlayerStateMachine.cs script (which is attached to the Player prefab and inherit the PlayerBaseState.cs) are not assigned the required values.

That would do it. We’re going to be adding a LOT of components to the PlayerStateMachine, and it’s important to assign them.

I hope the project files can be separated differently based on each lecture. Because the current project file structure is making me feel confused and just want to give up. This is really hard and moreover I don’t speak English on a daily basis.

Kind Regards,

Ari

If you look at the Resources on each lecture, you’ll see a link “This Lecture’s Project Changes”. This allows you to go to our GitLab repository and see hte specific changes we made to each script in the project. You can also clone the project and set the repo’s pointer on your system to match the lecture.

Privacy & Terms