I have an character (Ball_Class) and I want I want when he touches the actor (Jumper_Class) print message.
Ball_Class is have checked simulate physics
Jumper_Class.h:
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Components/StaticMeshComponent.h"
#include "Ball_Class.h"
#include "Components/BoxComponent.h"
#include "GameFramework/Actor.h"
#include "Jumper_Class.generated.h"
UCLASS()
class ROLLINGBALL_API AJumper_Class : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AJumper_Class();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
UPROPERTY(BlueprintReadOnly, VisibleAnywhere, Category = "JumperMesh")
UStaticMeshComponent* SM_Jumper;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
UBoxComponent* Box_Collision;
UFUNCTION()
void OnOverlapBegin(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
};
Jumper_Class.cpp:
// Fill out your copyright notice in the Description page of Project Settings.
#include "Jumper_Class.h"
#include "Components/BoxComponent.h"
// Sets default values
AJumper_Class::AJumper_Class()
{
// 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;
SM_Jumper = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("JumperStaticMesh"));
SM_Jumper->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
Box_Collision = CreateDefaultSubobject<UBoxComponent>(TEXT("BoxCollision"));
Box_Collision->SetBoxExtent(FVector(50.0f,50.0f,50.0f));
SM_Jumper->SetupAttachment(Box_Collision);
RootComponent = Box_Collision;
//RootComponent = SM_Jumper;
}
// Called when the game starts or when spawned
void AJumper_Class::BeginPlay()
{
Super::BeginPlay();
Box_Collision->OnComponentBeginOverlap.AddDynamic(this, &AJumper_Class::OnOverlapBegin);
}
// Called every frame
void AJumper_Class::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
void AJumper_Class::OnOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndexType, bool bFromSweep, const FHitResult& SweepResult)
{
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("qweqwe"));
if (OtherActor->ActorHasTag("RollingBall")) {
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("qwe"));
ABall_Class* MyRollingBall = Cast<ABall_Class>(OtherActor);
FVector ImpulseVector = FVector(0.0f, 0.0f, 50.0f);
MyRollingBall->GetCapsuleComponent()->AddImpulse(ImpulseVector, NAME_None, true);
}
}
As you can see, I have created Box_Collision and in the AJumper_Class::BeginPlay() function I have that line:
Box_Collision->OnComponentBeginOverlap.AddDynamic(this, &AJumper_Class::OnOverlapBegin);
but it’s not actually working, when my character is overlap Box_Collision, nothing is happend.