- Home /
How do i fix this?,How do i fix this script
NullReferenceException: Object reference not set to an instance of an object PlayerMotor.PerformMovement () (at Assets/PlayerMotor.cs:32) PlayerMotor.FixedUpdate () (at Assets/PlayerMotor.cs:24)
using UnityEngine;
[RequireComponent(typeof(Rigidbody))]
public class PlayerMotor : MonoBehaviour
{
private Vector3 velocity = Vector3.zero;
private Rigidbody rb;
void start()
{
rb = GetComponent<Rigidbody>();
}
public void Move(Vector3 _velocity)
{
velocity = _velocity;
}
void FixedUpdate()
{
PerformMovement();
}
void PerformMovement()
{
if (velocity != Vector3.zero)
{
rb.MovePosition(rb.position + velocity * Time.fixedDeltaTime);
}
}
}
When i do this it says NullReferenceException: Object reference not set to an instance of an object PlayerMotor.PerformMovement () (at Assets/PlayerMotor.cs:32) PlayerMotor.FixedUpdate () (at Assets/PlayerMotor.cs:24)
Answer by ShadyProductions · Dec 03, 2017 at 02:35 PM
You have to name your methods correctly so Unity can pick them up.
Its not void start()
but void Start()
because of this rb is never being set because unity can't find Start()
.
Also please format your code correctly in your question, I had to do it for you.
Your answer

Follow this Question
Related Questions
Windows Store [UWP] : error CS0246 0 Answers
Errors coming after putting the downloaded repository from bitbucket to Unity3d? 0 Answers
WaterBaseEditor.cs(11,17) 1 Answer
error 983 0 Answers
How can I load asset bundles that exceed 4GB via script? 0 Answers