Inserting a colision sphere to say a msg to the player

I´m Learning C++ in Unreal 4 with a book … and the examples are from Unreal 4.4

I having some problems with the compatibility, many of them was solved from foruns but this one i´m looking solution for hours and i can´t find

Here is the problem !

My code to insert a box colision to say a msg to the player when it´s hit it

.h file

UCLASS()
class GOLDENEGG_API ANPC : public ACharacter
{
	GENERATED_BODY()

	


public:
	// Sets default values for this character's properties
	ANPC(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer);

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

	// Called to bind functionality to input
	virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) override;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Collision) USphereComponent *ProxSphere;


	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = NPCMessage) FString NpcMessage;

	UFUNCTION(BlueprintNativeEvent, Category = "Collision")

	void Prox(AActor* OtherActor, UPrimitiveComponent* OtherComp, int32	OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult);
};

.cpp file

ANPC::ANPC(const FObjectInitializer& ObjectInitializer)
 : Super(ObjectInitializer)
{
	ProxSphere = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(this, TEXT("Proximity Sphere"));
	ProxSphere->AttachTo(RootComponent);
	ProxSphere->SetSphereRadius(32.f);
	//	Code	to	make	ANPC::Prox()	run	when	this	proximity	sphere
	//	overlaps	another	actor.
	ProxSphere->OnComponentBeginOverlap.AddDynamic(	this, &ANPC::Prox);
	NpcMessage = "Hi, I'm Owen";
	
	//default	message,	can	be	edited		//	in	blueprints 
}

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

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

}

// Called to bind functionality to input
void ANPC::SetupPlayerInputComponent(class UInputComponent* InputComponent)
{
	Super::SetupPlayerInputComponent(InputComponent);

}

void ANPC::Prox_Implementation(AActor* OtherActor, UPrimitiveComponent*	OtherComp, int32 OtherBodyIndex, bool bFromSweep, const	FHitResult	& SweepResult)
{
	    	
	if(	Cast<AAvatar>(OtherActor)==	nullptr)
	{
		return;
	}

	APlayerController* PController = GetWorld() -> GetFirstPlayerController();
	
	if (PController)
	{
		AMyHUD	* hud = Cast<AMyHUD>(PController->GetHUD());
		
		hud->addMessage(Message(NpcMessage, 5.f, FColor::White));
	}


}

Some one can give a light about what is wrong??

Hey there! I am going to provide a little bit of code that you can tweak to work for you. I’d also check to make sure the actors you are colliding with are set to work with Overlap Collisions.

I would go through your code but unfortunately I don’t have the time. So take mine instead and just double check the collisions. Cycle through the presets until it works. Also, try using GEngine->AddOnScreenDebugMessage to act as a check for you before calling your own functions. It’s a very reliable debug function. :slight_smile:

// 
// .h File
//

UPROPERTY(VisibleDefaultsOnly, Category = Projectile)
	class USphereComponent* CollisionComp;

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

/////////////////
////////////////

// .cpp File

void <YourClassNameHere>::OnOverlap(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
{
	//GEngine->AddOnScreenDebugMessage(-1, 5.0, FColor::White, FString::FString(OtherComp->GetName()));
	//GEngine->AddOnScreenDebugMessage(-1, 5.0, FColor::White, FString::FString(OtherActor->GetName()));
}

AConstructorCharacter::AConstructorCharacter()
{
  	CollisionComp = CreateDefaultSubobject<USphereComponent>(TEXT("SphereComp"));
	CollisionComp->InitSphereRadius(100.0f);
	CollisionComp->BodyInstance.SetCollisionProfileName("Collision");
	CollisionComp->OnComponentBeginOverlap.AddDynamic(this, &AYourClassNameHere::OnOverlap);
	CollisionComp->bGenerateOverlapEvents = true;
	CollisionComp->AttachTo(RootComponent);
}

Thx for suggestion

But i need to find my mistakes in my code, i want to learn c++ sintaxe … I know that there is a small mistake here … but i don t know where :confused:

Its a newbiee Question :wink:

Look closely at what I posted up compared to yours and you’ll find the mistake. :stuck_out_tongue:

LOL

I forgot the headers …

Newbiees … :/[

Thx for the clue :wink: