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.