Portals stop working

persistentobjects script says it’s not valid. however, I cannot see any errors. Any suggestions

using System;
using UnityEngine;
namespace RPG.Core
{
    public class PeristentObjectSpawner : MonoBehaviour
    {
        [SerializeField] GameObject persistentObjectPrefab;
        static bool hasSpawned = false;
        private void Awake() {
            if (hasSpawned) return;
            SpawnPersistentObjects();
            hasSpawned = true;
        }

        private void SpawnPersistentObjects()
        {
            GameObject persistentObject = Instantiate(persistentObjectPrefab);
            DontDestroyOnLoad(persistentObject);
        }
    }
}

Is it saying that the script isn’t valid when you try to drag it on to the PersistentObjectSpawner GameObject?

Make sure that the filename and the name of the script match.

Not sure what happened. However i rebuilt the script. but now the portals dont work and I just get an error
for my fader script NullReferenceException: Object reference not set to an instance of an object
RPG.SceneManagement.Fader+d__1.MoveNext () (at Assets/Scripts/SceneManagement/Fader.cs:14)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at :0)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
RPG.SceneManagement.Portal:OnTriggerEnter(Collider) (at Assets/Scripts/SceneManagement/Portal.cs:27)

here is my fader script

using System.Collections;
using UnityEngine;

namespace RPG.SceneManagement
{
    public class Fader : MonoBehaviour
    {

        CanvasGroup canvasGroup;


        public IEnumerator FadeOut(float time)
        {
            while (canvasGroup.alpha < 1)
            {
                canvasGroup.alpha += Time.deltaTime / time;
                yield return null;
            }
        }

        public IEnumerator FadeIn(float time)
        {
            while (canvasGroup.alpha > 0)
            {
                canvasGroup.alpha -= Time.deltaTime / time;
                yield return null;
            }
        }
    }
}

Solved ! nvm, sometimes I guess magic happens

Actually, when are you assigning the CanvasGroup?

Privacy & Terms