What do I do to fix this error I get it twice? I Want to make a player move in 2d.

I only have one script.

The Error:
NullReferenceException: Object reference not set to an instance of an object
UnityEngine.Rendering.Universal.UniversalAdditionalCameraData.get_scriptableRenderer () (at Library/PackageCache/com.unity.render-pipelines.universal@7.3.1/Runtime/UniversalAdditionalCameraData.cs:335)
UnityEditor.Experimental.Rendering.Universal.Light2DEditorUtility.GetRenderer2DData () (at Library/PackageCache/com.unity.render-pipelines.universal@7.3.1/Editor/2D/Light2DEditorUtility.cs:103)
UnityEditor.Experimental.Rendering.Universal.Light2DEditor.OnEnable () (at

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{

	public float speed = 5f;

	public Animator animator;
	public Rigidbody2D rb;

	Vector2 move;

	SpriteRenderer sr;

    // Start is called before the first frame update
    void Start()
    {
		sr = GetComponent<SpriteRenderer>();
    }

    // Update is called once per frame
    void Update()
    {
		move.x = Input.GetAxisRaw("Horizontal");

		animator.SetFloat("Speed", Mathf.Abs(move.x));

		if (Input.GetButtonDown("Fire1"))
		{
			animator.SetTrigger("Attack");
		}
    }

	private void FixedUpdate()
	{
		rb.MovePosition(rb.position + move * speed * Time.fixedDeltaTime);

		if (move.x < 0f)
		{
			sr.flipX = true;
		} else if (move.x > 0f)
		{
			sr.flipX = false;
		}
	}
}

A null reference exception means that you are trying to access members on an object which is null. So imagine you created a variable of type MyClass called myObject. MyClass has a property on it called MyProperty which you try to use but you didnt initialise myObject i.e.

MyClass myObject; 
myObject.MyProperty = "Some value";

This will give you a NullReferenceException because myObject is null and not an instance of MyClass.


p.s. The error will normally tell you what file, line and character the exception is happening on and the exception will generally have a call stack which tells you the order of the methods being called that lead up to the exception.


The way to fix it is to either remove the possibility for the object to be null or to add some null checks


Reading