Portal Transition issues (section 6 : 68-73)

To this point (#73 in the course) I have not heard mention if this feature will only work on a single terrain to another single terrain or not. Currently I have been attempting to move from terrain 1 (The Lake) to terrain 2 (The hideout) and then to terrain 3 (The Village). I didn’t think this would be an issue since both The Lake and The Village are in the same scene, yet returning from The Hideout to either other map just brings me to the first map I came from. Example, Lake to Hideout (good) Hideout to Village (Back to Lake terrain in a location near the other portal). or Vice versa, the same thing happens. I have gone over the videos 3-4 times looking for what could be the issue, yet have not had luck. Some assistance would be greatly appreciated.

Hey digger.

Saw your post on discord and then found you here as i had overlooked this.

Haver you check the persistant object prefab to make sure it has everything on it and also the secondary scenes have the event system.
If you can post the relavent code that was added in the lecture (using the code block aka curly braces here) and we can take a look.

Normally if you post this in the Q&A on Udemy i spot it sooner as it tends to get a little overlooked sometimes with them hiding under the unity tag.

I’m the same teaching assistant on the course btw so it both will come though to me regardless just Udemy has a panel this i have to hunt the list :slight_smile:
Anyways i digress lets take a look at that information and maybe someone will find the solution before i reply or i will be keeping tabs on this now to help solve it.

I’ve attached 2 images to help illustrate my issue as well.
Here is the script: {using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

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

    [SerializeField] int sceneToLoad = -1;
    [SerializeField] Transform spawnPoint;
    [SerializeField] DestinationIdentifier destination;

    private void OnTriggerEnter(Collider other) {
        if(other.tag == "Player") {
            StartCoroutine(Transition());
        }
    }

    private IEnumerator Transition() {
        if(sceneToLoad < 0) {
            Debug.LogError("Scene to load is not set");
            yield break;
        }
        

        DontDestroyOnLoad(gameObject);
        yield return SceneManager.LoadSceneAsync(sceneToLoad);

        Portal otherPortal = GetOtherPortal();
        updatePlayer(otherPortal);

        Destroy(gameObject);
    }
    
    private void updatePlayer(Portal otherPortal) {
        GameObject player = GameObject.FindWithTag("Player");
        player.transform.position = otherPortal.spawnPoint.position;
        player.transform.rotation = otherPortal.spawnPoint.rotation;
    }

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

}
}
To summarize, Scene 0 (AKA Sandbox one) has multiple terrains. terrain 1, “the lake”, holds trigger “A1”. It will take you to Scene 1 that holds “A2” and “B1” (AKA Sandbox two). Going back and fourth between these two triggers works fine. Likewise, going from terrain 2, “the Town”, that holds trigger B2 to B1 in “the Hideout” works fine. The issue is when you try and go from “the Lake” (A1) to “the Hideout” (A2), go through “the Hideout” and attempt to use trigger (B1) to exit to “the Town” (B2). The result is you teleport to “the Lake” instead, somewhere near where trigger B is on "the Town"s map. The same happens when going in reverse.
Though I’ve watched the videos numerous times, I’m sure it’s something simple that I’m missing. Just need a fresh pair of eyes to help me.


It’s very tricky to understand the issue here. I think a set of repro conditions (ideally a video) and a zip of the project would really help us out here.

First off, thanks for replying Sam.

As you requested, a zipped file of the game and a video file for your viewing enjoyment.
I will also mention, my enemies are running at max speed rather than what they are set to run at. this would be my next question once this portal issue was resolved.

Dropbox of Video File: https://www.dropbox.com/s/jhlrsny9ngcv218/Portal%20Test%207.mkv?dl=0
Dropbox of zipped files: https://www.dropbox.com/s/714g6hq35pxjq34/RPG%20Tutorial.zip?dl=0

Thanks.

Did some more tests and found that I can apparently only teleport to the terrain I start from.
Video link : https://youtu.be/9jN9rDkEbfg
Skip to 0:40 for first portal, 1:37 for second.

I’ve gone over the lectures again (3rd time) and can not seem to find any discrepancies in any of the code. I do wonder if something like the last reply in this thread would work for my situation?
Thread : Portals multiply and are incorrectly identified
I’m not sure if it would affect the code later down the road, specifically the save system.

This would have been a problem in our code too. The issue is that the NavMeshAgent is conflicting with the setting of the transform. You can fix by updating your code to:

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

I’ve changed made a note of this in the “Player Spawn Point” lecture at 7:30-9:19. Hopefully this should help future students not to stumble here.

By the way. Really nice work with your tutorial level. I love how long and expansive it feels.

1 Like

Awesome. Thank you sir. I’ll place this in to my code asap. As for the level… I think it’s the 20 years of Pen & Paper D&D DM-ing showing through… I’ll let you know if this works or not once I get a chance to implement it.

1 Like

Works perfectly. Thanks again.

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

Privacy & Terms