#Respawn Help
1 messages · Page 1 of 1 (latest)
what is the error is it the same, different?
same
singleton is destroyed?
probably the Nre
no
can't find the object with the tag? You set a tag and not layer?
yes
in the inspector, selecting the spawn point object, you set the tag to "spawn" on the object?
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
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"
this is your code right? https://gdl.space/ihejacuzir.cs
so in both Awake() and OnSceneLoaded() you're finding the object with "spawn" tag, not spawn1 or 2
k
but yeah it's not working and idk why
and your error was on like line 20 in Awake() yeah?
yes
Awake is getting called when you hit play, in scene 1
yeah
and it can't fnd that object, but you're saying a spawn point with "spawn" tag is in scene 1
but it doesn't work for the same reason not a new error??
yes
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
maybe try finding it a different way, var spawn = GameObject.Find("name of object");
ok
the l48 one might be because i didn't replace that with yours
@azure nacelle @slender pagoda wdyt?
yeah it can't find it by tag for whatever reason but looks like it found the first one in awake
yes
so replace the second with the same code
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
yeah
just renamed it to that
both objects are called Spawn
now this is just a theory
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
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
warnings should be fine
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
ah
normally if the singleton is like a spawnpointmanager script it would be on its own object
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
yeah it's super basic lol I dunno what is going wrong
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
Could just hard code the position instead of using the object
in OnSceneLoaded, you say transform.position = new Vector3(x,y,z); where x,y,z are the position of your spawn point
see here's the thing, if i do that, it won't work and i'll still just be sent back to the og position
so just look in the editor at where your spawn object is and take the x, y, z
i'll try it but i don't think it's gonna work because i still need a ddol
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
do i need ddol?
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
where am I putting that?
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
which i do
i'm lost
huh?
ok
so anyways now something is going definitely wrong
did what you said @scarlet otter https://gdl.space/epakacalix.cs
still error?
what happned
looks like you're falling through the ground
it's putting you there but it's too low, try moving the y axis up
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
you have a trigger on the object to trigger the scene switch?
i used oncollisionenter2d
like you walk into a trigger and it kicks off the scene switch
k
should work too
debug that it's being called
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?
Try removing it for now, you arent using it anyways
okay.
in onsceneload?
Instatiate(player, this.transform.position);put this code in Start() of your transform
this script is attatched to the player. should it?
Start() of "spawn"
so it should be on the spawn object?
make a new script, then just spawn the player directly in that spawn's position
damn my internet is shit
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
like return to a where you enter?
i guess. like you know what i mean right?
Actually I dont haha
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?
hmm.. that was very easy if you explained it from the beginning
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?
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
TeleportManager?
then you should have many transform.. each holds a teleporter script
i'm confused here
just a holder of array
so this is all one script?
that is 3 script
okay
help me walk through this
so teleporter and teleporter manager go to the spawn objects?
no.. only 1 manager, then many teleporter
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
And am i getting errors here because i didn't set it to an object?
what is the error saying?
ahh remove the static keyword here public static string PositionName = "";
ah nvm,, capitalize the t's here
use the proper loadscene of unity... I just wrote that as shortcut
but teleporterManager IS the TeleporterManager
that's the one we set
this was tp.transform.position
lol sorry Im writing via phone
this
the scene you want
ok
make sure if you have door on scene1 you have door in scene2
teleporter names must match
what it look like now
the objects in your scene
which objects?
ahh you havent asigned them yet
yes
an empty object? or an empty child of the player?
then make another empty, with trigger and teleporter
just empty
as long as it's in the scene
well here's one of the scenes
can I see the current code of manager?
the PositionName should be static
maybe we got misunderstanding earlier lol, I am split minded earlier haha
then I said this lol
and doing that gave me an error
because teleporterManager is the TeleporterManager we set
return the static, then capitalize those T
okay
And it... doesn't work
lol
same error as always
i wonder if this is just Unity fucking with me
weird, I dont get error
but i do when i run the game
everything is capitalized , what is the error you getting?
what error?
I'm getting this on the console
double click, where does it bring you
TeleporterManager.PositionName = collision.GetComponent<Teleporter>().PortalName;
ohh we forgot to if chekc if you hitting collider
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
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
do you have player in the second scene?
yes
what is the position?
of?
player
my teleporter or the player when i go to the scene?
he also have the playerteleporter script right?
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
if they have the script they should still teleport
go to scenemode, where is your teleporter?
see that white block?
it's weird now because now when i start the scene, i'm invisible
so i just.. completely turned invisible
i can move
ahh you are that white box?
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
...
anyways that issue's fixed, but i still don't end up at the telporter
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;
}
}
}
}```
okay so it works
but...
because i'm touching the teleporter always
i'm always teleporting there
ah you are switching scenees?
lol yeah we would want that lol
i see
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?
{
public string PortalName;
public int SceneIndex;
}```
i see... then only teleport when in that scene?
{
if(collider.CompareTag("teleporter"))
{
var temp = collision.GetComponent<Teleporter>();
TeleporterManager.PositionName = temp.PortalName;
SceneManager.LoadScene(temp.SceneIndex);
}
}```
it's not that i'm constantly switching scenes. it's that i'm constantly spawning at the teleporter when i DO switch the scene
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
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;
}
}```
well now i'm not spawning at the teleporter anymore
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;
}
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!
No prob.. I dont really use triggerenters, it's just way too expensive for me haha
I dont know howw to handle them well
Same
I wonder if this can be used for multiple scenes
Like changing to multiple scenes
sure