I’m in the middle of the Sword Visual Feedback lecture of the 2D RPG Unity course and am getting a NullReferenceException in my Unity console. Nothing appears to be wrong with the gameplay as a result, but the error keeps popping up whenever I hit play or return from Visual Studio. Here’s the full console message:
NullReferenceException: Object reference not set to an instance of an object
UnityEditor.Graphs.Edge.WakeUp () (at :0)
UnityEditor.Graphs.Graph.DoWakeUpEdges (System.Collections.Generic.List1[T] inEdges, System.Collections.Generic.List
1[T] ok, System.Collections.Generic.List`1[T] error, System.Boolean inEdgesUsedToBeValid) (at :0)
UnityEditor.Graphs.Graph.WakeUpEdges (System.Boolean clearSlotEdges) (at :0)
UnityEditor.Graphs.Graph.WakeUp (System.Boolean force) (at :0)
UnityEditor.Graphs.Graph.WakeUp () (at :0)
UnityEditor.Graphs.Graph.OnEnable () (at :0)
I have no clue the issue, but I believe it first showed up after making an edit to my sword Script (not sure exactly which edit), so here’s my current code for it:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Sword : MonoBehaviour
{
[SerializeField] private GameObject slashAnimPrefab;
[SerializeField] private Transform slashAnimSpawnPoint;
private PlayerControls playerControls;
private Animator myAnimator;
private PlayerController playerController;
private ActiveWeapon activeWeapon;
private GameObject slashAnim;
private void Awake()
{
playerController = GetComponentInParent<PlayerController>();
activeWeapon = GetComponentInParent<ActiveWeapon>();
myAnimator = GetComponent<Animator>();
playerControls = new PlayerControls();
}
private void OnEnable()
{
playerControls.Enable();
}
void Start()
{
playerControls.Combat.Attack.started += _ => Attack();
}
private void Update()
{
MouseFollowWithOffset();
}
private void Attack()
{
myAnimator.SetTrigger("Attack");
slashAnim = Instantiate(slashAnimPrefab, slashAnimSpawnPoint.position, Quaternion.identity);
slashAnim.transform.parent = this.transform.parent;
}
public void SwingUpFlipAnim()
{
slashAnim.gameObject.transform.rotation = Quaternion.Euler(-180, 0, 0);
if (playerController.FacingLeft)
{
slashAnim.GetComponent<SpriteRenderer>().flipX = true;
}
}
private void MouseFollowWithOffset()
{
Vector3 mousePos = Input.mousePosition;
Vector3 playerScreenPoint = Camera.main.WorldToScreenPoint(playerController.transform.position);
float angle = Mathf.Atan2(mousePos.y, mousePos.x) * Mathf.Rad2Deg;
if (mousePos.x < playerScreenPoint.x)
{
activeWeapon.transform.rotation = Quaternion.Euler(0, -180, angle);
}
else
{
activeWeapon.transform.rotation = Quaternion.Euler(0, 0, angle);
}
}
}
I am using Unity 2022.3.10f1 and would really appreciate any help with the issue; thanks!