NullReferenceException in Sword Visual Feedback lecture

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.List1[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!

Notably, double clicking the error does not lead or point me to any specific line of code or anything, but error messages pile up whenever I click on the SlashAnimSpawnPoint in my hierarchy… Still scratching my head and trying to decipher it, but here’s a screenshot in case it helps:

Double clicking some of the exceptions have brought this up in my Inspector, for what it’s worth:

image

It’s just a Unity error. See here:

1 Like

Alright, thanks!

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

Privacy & Terms