I’m trying to program a Brick Game and UE4 crash when the ball hit a brick.
The Box_Collision code line seem to cause problem. When I substract it, UE4 dont crash anymore.
void ABrickObject::BeginPlay()
{
Super::BeginPlay();
Box_Collision -> OnComponentBeginOverlap.AddDynamic(this, &ABrickObject::OnOverlapBegin);
}
That is the complete .cpp of my brick object:
// Fill out your copyright notice in the Description page of Project Settings.
#include "BrickObject.h"
#include "Components/StaticMeshComponent.h"
#include "Components/BoxComponent.h"
#include "Ball.h"
// Sets default values
ABrickObject::ABrickObject()
{
// 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_Brick = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Brick"));
SM_Brick ->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
Box_Collision = CreateDefaultSubobject<UBoxComponent>(TEXT("Box Collision"));
Box_Collision -> SetBoxExtent(FVector(25.0f, 10.0f, 10.0f));
Box_Collision -> SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
RootComponent = Box_Collision;
}
// Called when the game starts or when spawned
void ABrickObject::BeginPlay()
{
Super::BeginPlay();
Box_Collision -> OnComponentBeginOverlap.AddDynamic(this, &ABrickObject::OnOverlapBegin);
}
// Called every frame
void ABrickObject::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
void ABrickObject::OnOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndexType, bool bFromSweep, const FHitResult & SweepResult)
{
if (OtherActor -> ActorHasTag("Ball"))
{
ABall* MyBall = Cast<ABall>(OtherActor);
FVector BallVelocity = MyBall->GetVelocity();
BallVelocity *= (SpeedModifierOnBounce - 1.0f);
MyBall -> GetBall()-> SetPhysicsLinearVelocity(BallVelocity, true);
FTimerHandle UnusedHandle;
GetWorldTimerManager().SetTimer(UnusedHandle, this, &ABrickObject::DestroyBrick, 0.1f, false);
}
}
void ABrickObject::DestroyBrick()
{
this -> Destroy();
}
do you see what can be the problem?
Thanks for your help,