Download

[Help] OnOverlapBegin, Actor informartion

Hello Everyone,

now my problem is simple i believe but I have very limited knowledge in UE4 C++
I’d like to know how would i pull out the actor information which is overlapping with the current actor?


AHealthPack::AHealthPack(const FObjectInitializer& ObjectInitializer): Super(ObjectInitializer)
{
	HealthToAdd = 5;
	//ObjectInitializer
	bReplicates = true;
	CollisionSphere = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(this, TEXT("SphereComp"));
	CollisionSphere->InitSphereRadius(60.0f);
	RootComponent = CollisionSphere;
	CollisionSphere->OnComponentBeginOverlap.AddDynamic(this, &AHealthPack::OnOverlapBegin);
}


void AHealthPack::OnOverlapBegin(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
	if ((OtherActor != nullptr) && (OtherActor != this) && (OtherComp != nullptr)) 
	{
		Destroy();
	}
}

this is my ode trying to implement a health pack that will be destroyed once the actor is overlapping with it,
now i’d like to check if this player is player one or two?
also is there a way to give each player a unique ID in the network and use it to define which actor is who?

I’m new to this and trying to learn so please bare with me =D

Regards,
ALMansoori

If you know there are only ever going to be at most two players, all you really need to do is check whether the OtherActor is a Pawn (and whether it is controlled by a human player, so no AI, bots, etc.). You can do so by checking OtherActor->GetClass() against APawn::StaticClass() using the IsChildOf() function.

I’m assuming there is probably something like a unique ID but I don’t know where that would be. Worst case you’d have to give it one yourself.

If I understood you right, here’s what you should do:

  • On the overlapping method, as UnrealEverything said, just cross-check the class against the Actor’s class. Additionally, after you do so, you can typecast and compare:


if(otherActor->GetClass().Equals(APawn::StaticClass())
 if((Apawn*)otherActor == actorOwner)
  decay();


As for the IDs, you have to setup a factory and on the constructor - or better yet, when you spawn a player - initialize an ID based on an IDFactory.

Thanks I’ll try this once i get home =D
One more ting, is there a way to check based on Tags?

Edited: also i would not only have 2 players in a match, it will be up to 4 …

Regards,
ALMansoori