Why is my projectile breaking on respawn?

So I’ve created a very basic respawn system for my single-player game:
I’m just spawning my character at the location of one of the player starts, then possessing it.

For some reason though, my projectiles are sideways when I respawn, and the particle effect for the explosion always spawns at world zero.

I don’t understand how respawning could be affecting my projectile code at all. I’m just using a line trace to find the hit location before spawning it, so that shouldn’t ever change.

image

Out of curiosity: is this ever not valid?

As for the projectile: how are you spawning them and the explosion?

1 Like

I figured it out. I was calling the respawn from within my character bp and leaving the previous character dead on the ground. Unfortunately I didn’t realize this meant that the new character I spawned in was no longer index 0 so it broke my code anywhere I used a get player character node. How that affected my projectile I have no idea because it’s not reliant on the player. As soon as I moved the respawn to game instance, and destroyed the previous character before spawning the new one, it fixed the issue though.

I’m curious, is there a way to find out what index the current character is? I couldn’t find any nodes to do this. I thought I could grab the character’s index and set that as the new one but if there’s no way to know what index the character is it won’t work.

1 Like

If I remember correctly, GetAllActors gets registered actors in order of creation. So unless you loop through them and compare against another pointer, there is no way of knowing.

By moving the spawn to Gi, guess it boils down to storing the spawn in a variable to eventually destroy & set when needed.

1 Like

Yeah, that’s what I thought. Weird that there’s no way to query the character’s index. How do multiplayer games handle getting the correct character index? Like if you have a custom function inside a character that you want to call on the server? Maybe the answer is don’t have the function on your character?

Yeah, moving the function outside of the character allowed me to destroy the original before spawning the new one (which obviously you can’t do inside the character). I just chose the GI incase I wanted the ability to keep data across map changes. Figured I’ll just put everything I can in there.

Can’t help much with multiplayer, but this old post might: Spawn multiple player controllers in multiplayer game - #2 by anonymous_user_3cd4384c

1 Like

Yeah, I don’t know anything about mp either, but just like this post you linked to, every resource I could find online about the subject before posting only talks about the player controller not the player character. My guess is that the character is client side so you only ever need index 0 and you shouldn’t put code in your player character because it can change when you possess different ones etc.
It’s just ingrained in my head to code there because all the original Epic tutorials did it that way. Lol
Thanks for the help bud, and the discussion :slight_smile:

1 Like