Download

Spawn actor with parameters?

Hi,

Today I decided to go back to a little bit older of a project and work on it. It’s a multiplayer game, though EXTREMELY unfinished (I really only did it to teach myself some more ue4 c++.) The reason I stopped working on it in the first place is because I couldn’t find out how to stop bullets from hurting the person that shot them. I could always just spawn the bullets slightly farther from the shooter, and then make the bullets not bounce off walls, but I didn’t want to do that; I wanted to actually solve it.
So right now, I’m trying to let the projectile that is fired “know” which team it belongs to.
Lets say I’m on Team 1 and I shoot a bullet. It shouldn’t be able to damage any players on Team 1. I’m trying to do this by creating a team variable in the projectile, but I can’t figure out how to tell the projectile which team it’s on/cast the Team variable from the player to the projectile they fired.

Any ideas or help? Thanks!

After you spawn the bullet, call a function that initializes some of its values.

// spawn bullet
AMyBullet* Bullet = SpawnActor<AMyBullet>(MyBulletClass, Location, Rotation);

// call function on bullet (e.g. InitBullet)
Bullet.DoSomething();

Though I’d have the team number stored on the players. When spawning the bullet I’d set the player as the owner of that bullet. So later when the bullet hits something I would check if the hit player and the owner player are in different teams or not.

Thanks! I’m a little confused on your first explanation, though; would the code you provided be in the player.cpp or the projectile.cpp? (I’m not sure if “spawn” means spawn or after the projectile constructor)
Also, I’m pretty bad at c++. Could you explain to me how to set the owner of an actor when spawned? Sorry, and thanks again.