Quantcast
Channel: General - Epic Developer Community Forums
Viewing all articles
Browse latest Browse all 18355

Please a non dynamic variant for OnComponentBeginOverlap, OnComponentEndOverlap to support captured variable

$
0
0

As it stands ONLY dynamic overlap event exist for shape component used heavily in collision systems. It prevents me to include captured variable and must instead rely on caching the component in a map. Captured variables is normally possible with AddUObject or AddRaw for non dynamic delegates. Complicates some scenarios. Please see to this issue.

	UPROPERTY(BlueprintAssignable, Category="Collision")
	FComponentBeginOverlapSignature OnComponentBeginOverlap;

	UPROPERTY(BlueprintAssignable, Category="Collision")
	FComponentEndOverlapSignature OnComponentEndOverlap;

Use case:

FCourageManagedHitbox* UCourageHitboxManagerRuntimeComponent::GetOrAddHitbox(
USkeletalMeshComponent* SkeletalMeshComp
, const FString& SocketName
, const FString& Name
, ECourageHitboxType Type
)
{
	auto ManagedHitbox = _Hitboxes.Find(Name);
	if (!ManagedHitbox)
	{
		ManagedHitbox = &_Hitboxes.Add(Name, FCourageManagedHitbox());		
		ManagedHitbox->ExpectedType = Type;		
		ManagedHitbox->Shape == nullptr;
		if (Type == ECourageHitboxType::Box)
		{
			ManagedHitbox->BoxShape = NewObject<UBoxComponent>(this, UBoxComponent::StaticClass(), *Name);
			ManagedHitbox->Shape = ManagedHitbox->BoxShape;
		}
		else if (Type == ECourageHitboxType::Capsule)
		{
			ManagedHitbox->CapsuleShape = NewObject<UCapsuleComponent>(this, UCapsuleComponent::StaticClass(), *Name);
			ManagedHitbox->Shape = ManagedHitbox->CapsuleShape;
		}

		ManagedHitbox->Shape->RegisterComponent();
		ManagedHitbox->Shape->AttachToComponent(SkeletalMeshComp, FAttachmentTransformRules::SnapToTargetNotIncludingScale, *SocketName);
		ManagedHitbox->Shape->SetCollisionProfileName("OverlapAll", true);
		ManagedHitbox->Shape->SetGenerateOverlapEvents(true);
		_HitboxCache.Add(ManagedHitbox->Shape, ManagedHitbox);

		if (ManagedHitbox->Shape->OnComponentBeginOverlap.IsAlreadyBound(this, &UCourageHitboxManagerRuntimeComponent::OnOverlapBegin))
		{
			ManagedHitbox->Shape->OnComponentBeginOverlap.RemoveDynamic(this, &UCourageHitboxManagerRuntimeComponent::OnOverlapBegin);
		}

		ManagedHitbox->Shape->OnComponentBeginOverlap.AddDynamic(this, &UCourageHitboxManagerRuntimeComponent::OnOverlapBegin);
	}

	return ManagedHitbox;
}

void UCourageHitboxManagerRuntimeComponent::OnOverlapBegin(
UPrimitiveComponent* OverlappedComp
, AActor* OtherActor
, UPrimitiveComponent* OtherComp
, int32 OtherBodyIndex
, bool bFromSweep
, const FHitResult& SweepResult)
{
	if(auto ManagedHitbox = _HitboxCache.FindRef(OverlappedComp))
	{
		// DO something with the corresponding hitbox
	}	
}

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 18355

Trending Articles