Make projectile ignore player in multiplayer?

I’ve been searching for days and haven’t been able to find anything useful on this. I’m making a weapon that fires projectiles and when moving rapidly the projectile spawns inside the characters body. I want to get the projectile to ignore the player that created it but there seems to be no way to set an owner. All of the other answers to this question I’ve found either weren’t answers at all (e.g. you need to do this thing - no explanation of what that thing is) or are out of date to the point of uselessness and also don’t have any explanation.

Is there any way in blueprints to set the owner of a projectile or will I need to do something else such as turning off collisions for a period of time after spawning.

Hey,

I have been stuck on this a while, and initially I tried passing in the character pointer before I spawn the projectile but sometimes it was valid and others it was NULL. I then tried getting localplayercontroller(then get the pawn etc), but testing multiplayer under dedicated server, meant that both players would be the localcontroller.

Here is a quote from my solution, you might want to go to the link for additional info:

Right after I initially spawn the spell (to instantiate it and add it to my spell bar), I set the owner like so: (Mind you i had to set it on the server):

mychar.cpp:

 ASpellSystem* spell = GetWorld()->SpawnActor<ASpellSystem>(newSpell);
 spell->SetOwner(this);
 spellBar.Add(spell);

Then under my spell.cpp I set the Caster to:

Caster = Cast<MyChar>(GetOwner());

After this, I assigned a delegate to OnCompBegOverlap:

	collisionComp->OnComponentBeginOverlap.AddDynamic(this, &ASpellSystem::OnCollisionOverlapBegin);

I then check if the enemy that we collided with is != Caster, if so we call takedamage, (or apply dmg etc)

// Called when a spell collides with a player
void ASpellSystem::OnCollisionOverlapBegin(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
	ABBotCharacter* enemyPlayer = Cast<mychar>(OtherActor);
	if (enemyPlayer && enemyPlayer != Caster) {

           enemyPlayer->TakeDamage(ProcessElementalDmg(spellDataInfo.spellDamage), GetDamageEvent(), 0, this);
}

EDIT2:

I just read this for BluePrint, but essentially it would be the same thing, I would store the projectiles for the specific weapon in an array/variable, before which I would call SetOwner node with your character BP. So now every time you fire that projectile it already knows who its owner was and won’t collide with it. If you need additional help lmk and I will try to get a quick example out. I would suggest reading the C++ snippet, its very self explanatory.

*Make sure you set owner on the server.

Hope this helps you get started.

I was able to get it to work with this. I use SpawnActor in my character blueprint to spawn the projectile and in the projectile blueprint I use this check to make sure it doesn’t affect the character that fired it.

A little info on the setup: the projectile uses NoCollision has a lifespan of 2 seconds and is manually destroyed on overlap.