#Respawn Help

1 messages · Page 1 of 1 (latest)

lethal nexus
#

@azure nacelle @pseudo fossil @eternal schooner so even if i add a spawn object to both scenes i'm still getting an error

scarlet otter
#

what is the error is it the same, different?

lethal nexus
#

same

scarlet otter
#

singleton is destroyed?

azure nacelle
#

probably the Nre

lethal nexus
scarlet otter
#

can't find the object with the tag? You set a tag and not layer?

lethal nexus
scarlet otter
#

in the inspector, selecting the spawn point object, you set the tag to "spawn" on the object?

lethal nexus
#

yes

#

well it was on spawn2, because that's the one i'm colliding with to get to spawn

#

but even if i change that to spawn, i still get the same error

scarlet otter
#

you're looking for "spawn" in your code in awake (scene 1) and when it loads the scene in your scene callback when scene 2 is loaded

#

so it needs to be in both scenes with "spawn" and a different object with "spawn2"

lethal nexus
#

i'm confused

#

so both scenes need spawn1 and spawn2?

scarlet otter
lethal nexus
#

yeah lemme send the updated version

scarlet otter
#

so in both Awake() and OnSceneLoaded() you're finding the object with "spawn" tag, not spawn1 or 2

lethal nexus
#

oh yes

#

i meant spawn

#

not spawn1

scarlet otter
#

k

lethal nexus
#

but yeah it's not working and idk why

scarlet otter
#

and your error was on like line 20 in Awake() yeah?

lethal nexus
#

yes

scarlet otter
#

Awake is getting called when you hit play, in scene 1

lethal nexus
#

yeah

scarlet otter
#

and it can't fnd that object, but you're saying a spawn point with "spawn" tag is in scene 1

lethal nexus
#

yes

#

and even if i add that object there, it still doesn't work

scarlet otter
#

but it doesn't work for the same reason not a new error??

lethal nexus
#

yes

scarlet otter
#

In awake after you find the object add Debug.Log($"spawn null? {spawn ==null}");

#

and run it and does it say true

#

well nevermind

#

its null it's not going to get to the debug

lethal nexus
scarlet otter
#

maybe try finding it a different way, var spawn = GameObject.Find("name of object");

lethal nexus
#

ok

#

the l48 one might be because i didn't replace that with yours

#

@azure nacelle @slender pagoda wdyt?

scarlet otter
#

yeah it can't find it by tag for whatever reason but looks like it found the first one in awake

lethal nexus
#

yes

scarlet otter
#

so replace the second with the same code

lethal nexus
#

yeah i did

#

same error

scarlet otter
#

since you don't have dontdestroyonload on the spawn object it's not persisting into the other scene, does scene 2 have a spawn object with the same name

lethal nexus
#

yeah

#

just renamed it to that

#

both objects are called Spawn

#

now this is just a theory

scarlet otter
#

you could also just child the spawn point to the singleton and since it has don'tdestroyonload it will persist into scene 2, then you don't need that second find

lethal nexus
#

but i wonder if all these warnings might have something to do

#

even though they're irrelevant

#

it's for the font

#

and those aren't errors

scarlet otter
#

warnings should be fine

lethal nexus
#

yeah

#

so it's not that

#

wdym child the spawn point to the singleton?

scarlet otter
#

the spawn point is a gameobject in the scene? You drag it onto the object with the singleton script on it and it becomes a child

lethal nexus
#

oh okay

#

doesn't work

#

the player has the singleton

scarlet otter
#

ah

lethal nexus
#

there has to be an easier way to do this

#

let me tell you what i'm trying to do

scarlet otter
#

normally if the singleton is like a spawnpointmanager script it would be on its own object

lethal nexus
#

i'm trying to switch scenes but have my player spawn at a specific part of the scene when it loads

#

instead of just where you normally start

#

so kinda like a checkpoint

scarlet otter
#

yeah it's super basic lol I dunno what is going wrong

lethal nexus
#

so when i'm in one scene, i go to the next scene and spawn at a specific checkpoint

#

you think i should just restart from scratch?

#

because i don't think this is working?

#

if worse comes to worse, this is on a deadline so maybe just scrap it if i can't do it and then add it later?

#

but i would like to get it working before the deadline

#

because i still got a lot of stuff to do so i don't want to waste too much time on this

scarlet otter
#

Could just hard code the position instead of using the object

lethal nexus
#

wdym?

#

like do it the old fashioned way?

scarlet otter
#

in OnSceneLoaded, you say transform.position = new Vector3(x,y,z); where x,y,z are the position of your spawn point

lethal nexus
scarlet otter
#

so just look in the editor at where your spawn object is and take the x, y, z

lethal nexus
scarlet otter
#

in OnSceneLoad you'd check to see which scene it is and could specify a different position depending on scene

#

but it should have worked how you had it with finding the spawn point

lethal nexus
#

do i need ddol?

azure nacelle
#
        spawnpoint = GameObject.FindGameObjectWithTag("spawn").transform;
        spawnpoint.position = GameObject.FindGameObjectWithTag("spawn").transform.position;
        Debug.Log(spawnpoint.position)
        transform.position = spawnpoint.position;
```Try this if it actually log the right place
lethal nexus
#

where am I putting that?

azure nacelle
# lethal nexus do i need ddol?

as I see now you dont really now.. I only said it earlier because you said the player have to go from one scene to another

azure nacelle
#

DDOL would be useful if the player know whre it want to spawn

#

from scene 1

lethal nexus
#

i'm lost

#

huh?

#

ok

#

so anyways now something is going definitely wrong

scarlet otter
#

still error?

azure nacelle
#

what happned

lethal nexus
#

swear i'm boutta go Karen

scarlet otter
#

looks like you're falling through the ground

lethal nexus
#

yeah

#

so i'm getting rid of the vector

scarlet otter
#

it's putting you there but it's too low, try moving the y axis up

lethal nexus
#

no, it's not even sending me to the scene

#

the scene i want to go to

#

dammit all of this for a simple action

#

touch the object, go to respawn point at next scene

#

wtf is so hard?

#

why does unity hate me lol

scarlet otter
#

you have a trigger on the object to trigger the scene switch?

lethal nexus
#

i used oncollisionenter2d

scarlet otter
#

like you walk into a trigger and it kicks off the scene switch

#

k

#

should work too

#

debug that it's being called

lethal nexus
#

and it does

#

but not with the vector method

#

for some reason

#

@azure nacelle should i use ddol?

#

is anyone here?

#

@scarlet otter you here?

azure nacelle
lethal nexus
#

okay.

azure nacelle
#

just instantiate the player on the Spawn

#

as easy as that

lethal nexus
#

in onsceneload?

azure nacelle
#

Instatiate(player, this.transform.position);put this code in Start() of your transform

lethal nexus
#

this script is attatched to the player. should it?

azure nacelle
#

Start() of "spawn"

lethal nexus
#

so it should be on the spawn object?

azure nacelle
#

make a new script, then just spawn the player directly in that spawn's position

#

damn my internet is shit

lethal nexus
#

okay let me figure this out.
the script i have:
player touches the spawn script...
it loads the scene

#

then...

#

but wait, then i'll always load at the spawn point right?

#

like no matter what?

#

GRAAH i'm confused

#

because @azure nacelle let's say, i start the scene at an og position, i go to the object that'll take me to another scene, then i touch an object from there that'll take me to the previous scene but at a respawn point

#

that is what i'm trying to do

azure nacelle
lethal nexus
azure nacelle
#

Actually I dont haha

lethal nexus
#

like if i climb a ladder that'll take me to the next scene, if i go back down, it'll take me to the top of the steps of the previous scene?

azure nacelle
lethal nexus
#

sorry

#

tried this but i'm saying now i'm trying to access a destroyed singleton

#

it's saying the script was destroyed tho i'm still trying to access it. weird

#

@azure nacelle you know what it could be?

#

@azure nacelle you there?

azure nacelle
#
public class Teleporter : MonoBehaviour
{
    public string PortalName;
}

public class TeleporterManager : MonoBehaviour
{
    public static string PositionName = "";
    public Teleporter[] teleporters; // Fill in the inspector
}

public class Player : MonoBehaviour
{
    public TeleporterManager teleporterManager

    void Awake()
    {
        if(teleporterManager.PositionName != "")
        {
            foreach(Teleporter tp in teleporterManager.teleporters)
            {
                if(teleporterManager.PositionName == tp.PortalName)
                {
                    transform.position = tp.position;
                }
            }
        }
    }

    void OnTriggerEnter2D(blah)
    {
        teleporterManager.PositionName = blah.GetComponent<Teleporter>().PortalName;
        LoadScene();
    }
}```
#

every scene should have a Player, and TeleportManager

lethal nexus
#

TeleportManager?

azure nacelle
#

then you should have many transform.. each holds a teleporter script

lethal nexus
#

i'm confused here

azure nacelle
#

just a holder of array

lethal nexus
#

so this is all one script?

azure nacelle
#

that is 3 script

lethal nexus
#

okay

#

help me walk through this

#

so teleporter and teleporter manager go to the spawn objects?

azure nacelle
#

no.. only 1 manager, then many teleporter

lethal nexus
#

so the manager is...

#

a parent?

#

oh wait

#

so it's an array

azure nacelle
#

door is the name

#

of the teleporter's PortalName

#

if you enter a door, in one place, you should go to the door of another scene

#

you need to have a player object in both scenes

lethal nexus
#

And am i getting errors here because i didn't set it to an object?

azure nacelle
#

what is the error saying?

lethal nexus
azure nacelle
#

ahh remove the static keyword here public static string PositionName = "";

lethal nexus
#

here's this one

#

and this one

azure nacelle
#

ah nvm,, capitalize the t's here

azure nacelle
lethal nexus
#

that's the one we set

azure nacelle
#

lol sorry Im writing via phone

lethal nexus
#

it's cool

#

how bout the LoadScene error?

lethal nexus
#

oh

#

so i set it to what? the scene i want to go to?

azure nacelle
#

the scene you want

lethal nexus
#

ok

azure nacelle
#

make sure if you have door on scene1 you have door in scene2

#

teleporter names must match

lethal nexus
#

right

#

so then what do i do?

azure nacelle
#

what it look like now

lethal nexus
#

?

#

so where do i assign these scripts?

azure nacelle
#

the objects in your scene

lethal nexus
#

which objects?

azure nacelle
#

ahh you havent asigned them yet

lethal nexus
#

yes

azure nacelle
#

put the player code in your player

#

then make an empty, add the manager there

lethal nexus
#

an empty object? or an empty child of the player?

azure nacelle
#

then make another empty, with trigger and teleporter

#

just empty

#

as long as it's in the scene

lethal nexus
#

okay so then what?

#

i assign them

azure nacelle
#

screenshot?

#

of the heirarchy

lethal nexus
#

well here's one of the scenes

azure nacelle
#

the PositionName should be static

#

maybe we got misunderstanding earlier lol, I am split minded earlier haha

lethal nexus
azure nacelle
lethal nexus
#

because teleporterManager is the TeleporterManager we set

azure nacelle
#

return the static, then capitalize those T

lethal nexus
#

And it... doesn't work

#

lol

#

same error as always

#

i wonder if this is just Unity fucking with me

azure nacelle
#

Copy paste the whole code

#

my laptop is open now

lethal nexus
#

i'll copy paste all three

#

just give me a second

azure nacelle
#

weird, I dont get error

lethal nexus
#

but i do when i run the game

azure nacelle
#

everything is capitalized , what is the error you getting?

azure nacelle
lethal nexus
#

I'm getting this on the console

azure nacelle
#

double click, where does it bring you

lethal nexus
#

TeleporterManager.PositionName = collision.GetComponent<Teleporter>().PortalName;

azure nacelle
#

ohh we forgot to if chekc if you hitting collider

lethal nexus
#

oh

#

what do i do for that?

azure nacelle
#
    void OnTriggerEnter2D(Collider2D collision)
    {
        if(collider.CompareTag("teleporter"))
        {
            TeleporterManager.PositionName = collision.GetComponent<Teleporter>().PortalName;
            SceneManager.LoadScene("SampleScene");
        }
    }```
#

and im sure yuo know what to do with tag

lethal nexus
#

i'm 99% sure this is gonna give me the same error but worth a shot lol

#

Okay so it's sending me to the scene, but not to the teleporter also i'm invisible

azure nacelle
#

do you have player in the second scene?

lethal nexus
#

yes

azure nacelle
#

what is the position?

lethal nexus
#

of?

azure nacelle
#

player

lethal nexus
#

my teleporter or the player when i go to the scene?

azure nacelle
#

he also have the playerteleporter script right?

lethal nexus
#

yes

#

although

#

it's a prefab of the player

#

the player i made into a prefab

#

should i not have done that?

#

i mean both scenes have a player object

#

but maybe it's because they're not the SAME player object?

#

idk it's weird

azure nacelle
#

if they have the script they should still teleport

lethal nexus
#

yeah

#

so why is he invisible and at a different position?

azure nacelle
#

go to scenemode, where is your teleporter?

lethal nexus
#

see that white block?

#

it's weird now because now when i start the scene, i'm invisible

#

so i just.. completely turned invisible

azure nacelle
#

can you move?

#

how tf you become invi lol

lethal nexus
#

i can move

azure nacelle
#

ahh you are that white box?

lethal nexus
#

no

#

the white box is where the teleporter's position is

#

i'm the purple guy

#

oh fuck i know the problem

#

camera wasn't aligned with player

#

it was so fucking far away lol

azure nacelle
#

...

lethal nexus
#

anyways that issue's fixed, but i still don't end up at the telporter

azure nacelle
#

change the Awake() to start()

#

maybe another script is changing your position on Awake() or onenable()

#
void Start()
    {
        if (TeleporterManager.PositionName != "")
        {
            foreach (Teleporter tp in teleporterManager.teleporters)
            {
                if (TeleporterManager.PositionName == tp.PortalName)
                {
                    Debug.Log("Match found!");
                    transform.position = tp.transform.position;
                    break;
                }
            }
        }
    }```
lethal nexus
#

okay so it works

#

but...

#

because i'm touching the teleporter always

#

i'm always teleporting there

azure nacelle
#

ah you are switching scenees?

lethal nexus
#

yes

#

well

azure nacelle
#

lol yeah we would want that lol

lethal nexus
#

not switching scenes

#

just always spawning at that one scene

azure nacelle
#

i see

lethal nexus
#

wonder if after i touch it, i change the layer of the teleporter to something i can't touch... but then i'll never be able to telport again tho right?

azure nacelle
#
{
    public string PortalName;
    public int SceneIndex;
}```
lethal nexus
#

i see... then only teleport when in that scene?

azure nacelle
#
    {
        if(collider.CompareTag("teleporter"))
        {
            var temp = collision.GetComponent<Teleporter>();
            TeleporterManager.PositionName = temp.PortalName;
            SceneManager.LoadScene(temp.SceneIndex);
        }
    }```
lethal nexus
#

so i'm at the same scene. i'm just always teleporting to the teleporter

#

so it's like i'm always starting the scene

azure nacelle
#
    void OnTriggerEnter2D(Collider2D collision)
    {
        if(collider.CompareTag("teleporter") && canTp)
        {
            var temp = collision.GetComponent<Teleporter>();
            TeleporterManager.PositionName = temp.PortalName;
            SceneManager.LoadScene(temp.SceneIndex);
        }
    }

    bool canTp = false;
    void OnTriggerExit2D(bla)
    {
        if(collider.CompareTag("teleporter"))
        {
            canTp = true;
        }
    }```
lethal nexus
azure nacelle
#
    void Start()
    {
        if (TeleporterManager.PositionName != "")
        {
            foreach (Teleporter tp in teleporterManager.teleporters)
            {
                if (TeleporterManager.PositionName == tp.PortalName)
                {
                    Debug.Log("Match found!");
                    transform.position = tp.transform.position;
                    break;
                }
            }
        }
        Invoke("delaytele", 3);
    }

    void delaytele()
    {
        canTp = true;
    }
lethal nexus
#

i think i got it

#

i just set the teleporter i DON'T want to touch to teleport to an untouchable layer

#

therefore, i can teleport there and NOT touch it to teleport

#

so i think it's working

#

yeah unless it's just unity glitching, it seems to work fine

#

this script ain't perfect but it does work!

#

I can't thank you enough, man! I really appreciate it!

azure nacelle
#

No prob.. I dont really use triggerenters, it's just way too expensive for me haha

#

I dont know howw to handle them well

lethal nexus
#

Same

#

I wonder if this can be used for multiple scenes

#

Like changing to multiple scenes

azure nacelle
lethal nexus
#

I guess you could with some more work but for now I’ll keep it to this

#

Thanks again. I’ll let you know if anything comes up

azure nacelle
#

aslong as the sceneindex of teleporter is in the build setting

#

also make sure that that scene have the proper teleporter with same name