I made a simple box component for my character to see which actors stand next to it. But somehow I don’t get it to work, respectively the class doesn’t recognize the component… even though I can see it in the editor. Here is my code:
SomCharacter.h
UCLASS()
class STRUGGLEOFMAGES_API ASomCharacter : public ACharacter
{
GENERATED_UCLASS_BODY()
//Declare the Vicinity Box
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Volumes)
UBoxComponent* VicinityBox;
}
//A Function to get all the actors nearby
UFUNCTION(BlueprintCallable, Category = Interaction)
TArray<AActor*> GetVicinityInteractables();
SomCharacter.cpp
ASomCharacter::ASomCharacter(const class FObjectInitializer& PCIP)
: Super(PCIP)
{
//Create the vicinity box and set its attributes
VicinityBox = PCIP.CreateDefaultSubobject<UBoxComponent>(this, TEXT("Vicinity_Box"));
VicinityBox->AttachTo(RootComponent);
VicinityBox->AddLocalOffset(FVector(70.0, 0.0, 0.0));
VicinityBox->SetBoxExtent(FVector(50.0, 60.0, 100.0));
VicinityBox->SetHiddenInGame(false);
}
TArray<AActor*> ASomCharacter::GetVicinityInteractables()
{
TArray<AActor*> CollectedActors;
//Collect ALL Actors in the VicinityBox
if (VicinityBox)
VicinityBox->GetOverlappingActors(CollectedActors);
else
print("No Vicinity box found!");
return CollectedActors;
}
If I execute the GetVicinityInteractables()-Function in Blueprints, it always prints out “No Vicinity box found!” … does anybody know, what the problem could be? Thanks in advance