Hi! I’m fairly new to coding and I have been working on expanding the RPG Creator Kit! I added in a menu system that gives you the option to change the volume, and an option to load the game.
However, when I first load the game everything is fine. But the moment I click the main menu button and reload the game scene a “Missing Reference Exception” error occurs.
This is the error that is displayed: MissingReferenceException: The object of type ‘FadingSprite’ has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object.
And finally, this is the code that the error is linked to:
using System.Collections.Generic;
using UnityEngine;
namespace RPGM.Gameplay
{
/// <summary>
/// A system for batch animation of fading sprites.
/// </summary>
public class FadingSpriteSystem : MonoBehaviour
{
void Update()
{
foreach (var c in FadingSprite.Instances)
{
if (c.gameObject.activeSelf)
{
c.alpha = Mathf.SmoothDamp(c.alpha, c.targetAlpha, ref c.velocity, 0.1f, 1f);
c.spriteRenderer.color = new Color(1, 1, 1, c.alpha);
}
}
}
}
}