Skip to content

Instantly share code, notes, and snippets.

@HappyZombies
Created January 29, 2017 18:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HappyZombies/b6a6007bf6051a19160223b0ff0ecf3d to your computer and use it in GitHub Desktop.
Save HappyZombies/b6a6007bf6051a19160223b0ff0ecf3d to your computer and use it in GitHub Desktop.
Unreal Engine simple Overlap sample
// Fill out your copyright notice in the Description page of Project Settings.
#include "Jack.h"
#include "Pad.h"
// Sets default values
APad::APad()
{
// 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;
padRoot = CreateDefaultSubobject<USceneComponent>(TEXT("PickUpRoot"));
RootComponent = padRoot;
myMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("myMesh"));
myMesh->AttachToComponent(padRoot, FAttachmentTransformRules::SnapToTargetNotIncludingScale);
padBox = CreateDefaultSubobject<UBoxComponent>(TEXT("PickUpBox"));
padBox->SetWorldScale3D(FVector(1.0f, 1.0f, 1.0f));
padBox->bGenerateOverlapEvents = true;
padBox->OnComponentBeginOverlap.AddDynamic(this, &APad::onPlayerEnterPadBox);
padBox->AttachToComponent(padRoot, FAttachmentTransformRules::SnapToTargetNotIncludingScale);
}
// Called when the game starts or when spawned
void APad::BeginPlay()
{
}
// Called every frame
void APad::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
}
void APad::onPlayerEnterPadBox(UPrimitiveComponent* OverlappedComp, AActor* otherActor, UPrimitiveComponent* otherComp, int32 otherBodyIndex, bool bFromSweep, const FHitResult& sweepResult)
{
FString name = OverlappedComp->GetName();
uint32 id = OverlappedComp->GetUniqueID();
UE_LOG(LogTemp, Warning, TEXT("%d is the id for the box you entered."), id);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment