Portal Issues

When I go through the portal on the original scene, I enter the sandbox2 without the alpha decreasing, although, when I go from sandbox2 to the original scene, it works fine. And not just with portals. Remembering the health between scenes only works this was as well.

Some images if needed:

Overall Preview:

Fader on Main Scene:

Fader of Sandbox2:

Have you gotten to the point where the PersistentObjectPrefab is created? The Fader should be in the PeristentObjectsPrefab, and not within either of the scenes.

Yes, at the start of the game the persistentObjects prefab is loaded into the scene with the fader in it

do you need to see the code?

I think it’s simpler than that… the reason I had asked is because you shared a screenshot of the Fader on Scene 1 and the Fader on Scene 2… They should be the same fader, and it should only exist in the PersistentObjectsPrefab. Check both scene files to ensure that there isn’t a fader object hiding in them.

I’ve just checked and there are no faders in both scenes

1st scene:
image

2nd scene:
image

Ok, was just the posting of two fader objects screenshots was throwing me… I didn’t ahve to context to see if they were in the DontDestroyOnLoad section.

99 times out of 100, this is the issue… so I jumped the gun…
Let’s dig a bit further…

Are there any error messages in the console when you transition from Scene 1 to Scene 2?

Does the Player in both scenes have identical identifiers (“player”) in the SaveableEntity?

Paste in your Portal.cs script.

I get this error:
image

Yes, they do have the same identifier

the Portal.cs:

type or paste code here
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Analytics;
using UnityEngine.SceneManagement;
using UnityEngine.AI;

namespace RPG.SceneManagment
{
    public class Portal : MonoBehaviour
    {
        enum DestinationIdentifier
        {
            A, B, C, D, E
        }

        [SerializeField] private int sceneIndex = -1;
        [SerializeField] private Transform spawnPoint;
        [SerializeField] DestinationIdentifier destination;
        [SerializeField] float fadeOutTime = 1f;
        [SerializeField] float fadeInTime = 2f;
        [SerializeField] float fadeWaitTime = .5f;
        private void OnTriggerEnter(Collider other)
        {
            if (other.tag == "Player")
            {
                StartCoroutine(Transition());
            }
        }

        private IEnumerator Transition()
        {

            if(sceneIndex < 0)
            {
                Debug.LogError("SceneIndex not set");
                yield break;
            }

            DontDestroyOnLoad(this.gameObject);

            Fader fader = FindObjectOfType<Fader>();

            yield return fader.FadeOut(fadeOutTime);

            SavingWrapper wrapper = FindObjectOfType<SavingWrapper>();
            wrapper.Save();

            yield return SceneManager.LoadSceneAsync(sceneIndex);

            wrapper.Load();

            Portal otherPortal = GetOtherPortal();
            UpdatePlayer(otherPortal);

            yield return new WaitForSeconds(fadeWaitTime);
            yield return fader.FadeIn(fadeInTime);

            Destroy(this.gameObject);
            
        }

        private void UpdatePlayer(Portal otherPortal)
        {
            GameObject player = GameObject.FindWithTag("Player");
            player.GetComponent<NavMeshAgent>().enabled = false;
            player.transform.position = otherPortal.spawnPoint.position;
            player.transform.rotation = otherPortal.spawnPoint.rotation;
            player.GetComponent<NavMeshAgent>().enabled = true;
        }

        private Portal GetOtherPortal()
        {
            foreach (Portal portal in FindObjectsOfType<Portal>())
            {
                if (portal == this) continue;
                if (portal.destination != destination) continue;

                return portal;
            }

            return null;
        }
    }
}

ah, there’s your problem. It happened to me, and based on other posts, to other people.

The portal cannot be place as a child under another game object in the hierarchy. It has to be top level.

Ohh, so I have to take it out of the core empty game object in my scene

The message is trying to tell you that the Portal is under another GameObject (not at the root of the heirarchy). One of the quirks of DontDestroyOnLoad is that it only works on GameObjects at the root. One of the annoying things in Unity is that they chose to make this a “warning” instead of escalating the message to an error.

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

Privacy & Terms