Hey I am trying to make it so when another actor enters my collision sphere it does 2 functions, but it doesn’t call the second one.
Code for the character.h
// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
#pragma once
#include "GameFramework/Character.h"
#include "Pickup.h"
#include "Interactables.h"
#include "RPGCharacter.generated.h"
UCLASS(Blueprintable)
class ARPGCharacter : public ACharacter
{
GENERATED_BODY()
public:
ARPGCharacter();
// Called every frame.
virtual void Tick(float DeltaSeconds) override;
/** Returns TopDownCameraComponent subobject **/
FORCEINLINE class UCameraComponent* GetTopDownCameraComponent() const { return TopDownCameraComponent; }
/** Returns CameraBoom subobject **/
FORCEINLINE class USpringArmComponent* GetCameraBoom() const { return CameraBoom; }
/** Returns CursorToWorld subobject **/
FORCEINLINE class UDecalComponent* GetCursorToWorld() { return CursorToWorld; }
//------------------------------------------------------------ COLLISION SPHERE CODE-------------------------------------------------
//Loot Sphere
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Player Collision Sphere")
USphereComponent* PCollisionSphere;
UFUNCTION()
void TZ_Enter(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult);
UFUNCTION()
void Loot_Pickup(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult);
The CPP File
//Player Collision Sphere
PCollisionSphere = CreateDefaultSubobject<USphereComponent>(TEXT("Player Collision Sphere")); // Declares the Collision Sphere
PCollisionSphere->bGenerateOverlapEvents = true; // Allows the sphere to generate overlap events
PCollisionSphere->SetSphereRadius(200.f); // Sets the radius
PCollisionSphere->OnComponentBeginOverlap.AddDynamic(this, &ARPGCharacter::TZ_Enter); //Function called from this class
PCollisionSphere->OnComponentBeginOverlap.AddDynamic(this, &ARPGCharacter::Loot_Pickup);
PCollisionSphere->SetupAttachment(RootComponent); // Attaches the Collision Sphere to the root component what is it in this case I HAVE NO IDEA :D
PCollisionSphere->SetHiddenInGame(false); // Shows the sphere in game (For debugging purposes)
void ARPGCharacter::TZ_Enter(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
{
if (!OtherActor->IsA(ACharacter::StaticClass())) // Checks to see if the other actor is not a character
{
GEngine->AddOnScreenDebugMessage(1, 5.f, FColor::Purple, "Overlapped Some Shiz"); // Displays a debug message
}
}
void ARPGCharacter::Loot_Pickup(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
{
if (!OtherActor->IsA(ACharacter::StaticClass()) && OtherActor->IsA(APickup::StaticClass()) )
{
GEngine->AddOnScreenDebugMessage(1, 5.f, FColor::Yellow, "Enterd");
APickup* CurrentPickup = Cast<APickup>(OtherActor);
CurrentPickup->onPickedup();
}
}
The function i am trying to get working but isent
PCollisionSphere->OnComponentBeginOverlap.AddDynamic(this, &ARPGCharacter::Loot_Pickup);
void ARPGCharacter::Loot_Pickup(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
{
if (!OtherActor->IsA(ACharacter::StaticClass()) && OtherActor->IsA(APickup::StaticClass()) )
{
GEngine->AddOnScreenDebugMessage(1, 5.f, FColor::Yellow, "Enterd");
APickup* CurrentPickup = Cast<APickup>(OtherActor);
CurrentPickup->onPickedup();
}
}
Even if i comment out this line of code (A function call) it still outputs the code for the function !!!
PCollisionSphere->OnComponentBeginOverlap.AddDynamic(this, &ARPGCharacter::TZ_Enter); //Function called from this class
Thanks for the help in advanced
I get no compile errors btw