Download

Crashing issue after using OnComponentBeginOverlap.AddDynamic

Hey, so since I have programmed this code:



AFloatingPickUp::AFloatingPickUp()
{
 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

	itemRoot = CreateDefaultSubobject<USceneComponent>(TEXT("ItemRoot"));

	RootComponent = itemRoot;

	pickUpItem = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("PickUpItem"));
	pickUpItem->AttachToComponent(itemRoot, FAttachmentTransformRules::SnapToTargetNotIncludingScale);

	rootShape = CreateDefaultSubobject<UShapeComponent>(TEXT("RootShape"));
	rootShape->SetWorldScale3D(FVector (1.0f, 1.0f, 1.0f));
	rootShape->bGenerateOverlapEvents = true;
	rootShape->OnComponentBeginOverlap.AddDynamic(this, &AFloatingPickUp::onPlayerEnterPickUpBox);
	rootShape->AttachToComponent(itemRoot, FAttachmentTransformRules::SnapToTargetIncludingScale);


}


Unreal 4 crashes and I cannot reopen the file. Anyone else experiencing this? And any help I can get would be much appreciated as I am a Unreal 4 noob.

Thanks!

What is the crash you are getting? It should tell you when you try to run the game project from Visual Studio as to why it can’t run or on what line it crashes.

Make sure OnPlayerEnterPickupBox() is a UFUNCTION.

If you check the output window in VS, it does tell you why it’s crashed.