Download

Finish Line

Hello guys. I have this problem. I want to make a Box, to, when fallen into the box, set you back to the spawnpoint and play a sound. However, I can’t seem to get it compiled. Code:


// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "GameFramework/Actor.h"
#include "BlockActor.generated.h"

UCLASS()
class MYPROJECT2_API ABlockActor : public AActor
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	ABlockActor();

	// Called when the game starts or when spawned
	virtual void BeginPlay() override;
	
	// Called every frame
	virtual void Tick( float DeltaSeconds ) override;

	//The static mesh for the pickup

	UShapeComponent* FinishLineBox;
	UPROPERTY(EditAnywhere)
		USoundBase *FinishSound;
	UFUNCTION()
		void TriggerEnter(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult);

	
};



// Fill out your copyright notice in the Description page of Project Settings.

#include "MyProject2.h"
#include "BlockActor.h"


// Sets default values
ABlockActor::ABlockActor()
{
 	// 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;
	FinishLineBox = CreateDefaultSubobject<UBoxComponent>(TEXT("FinishBox"));
	RootComponent = FinishLineBox;

	FinishLineBox->bGenerateOverlapEvents = true;
	FinishLineBox->OnComponentBeginOverlap.AddDynamic(this, &ABlockActor::TriggerEnter);
}

// Called when the game starts or when spawned
void ABlockActor::BeginPlay()
{
	Super::BeginPlay();
	
}

// Called every frame
void ABlockActor::Tick( float DeltaTime )
{
	Super::Tick( DeltaTime );

}

void TriggerEnter(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
{
	if (OtherActor->IsA(ACharacter::StaticClass())) {
		UGamePlayStatics::PlaySoundAttached(FinishSound, OtherActor->GetRootComponent());
	}
}



Thanks in advance.

Nobody who can help me?

What compiler errors are you receiving? Posting those will help figure out where the problem is.

These are my error logs:

First of all, while compiling in the Editor (aka Hot Reloading) is possible, you should not do that very often.
Only do it for minor changes.

Better way to do it is to close your Engine Editor (booting it up again takes a few seconds) and to compile the code in VS.

You do this by rightclicking your project on the right side in the Solution browser and hitting “Build”.

If that’s done, your binaries are updated and you can start the Engine again. You can also close VS if you don’t
need to make any C++ changes during the day.

Now to your problem:

It looks like you are using the wrong function parameters for the overlap functions.

You use “OtherActor” and “OtherComp”, so “AActor” and “UPrimitiveComponent”.

The error tells you that the correct parameters need an additional one.

At some point, Epic changes the overlap functions to also give you the actual component of that the Actor itself. So you know who
actually overlapped (could be that two components use the same overlap function, right? :P)

So it should be this:



UFUNCTION()
	void TriggerEnter(class UPrimitiveComponent* ThisComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult);



At least I think it was that order. :stuck_out_tongue: