I am very new with C++ and Unreal Engine 4.
I am creating a pickup script with a box collider and I have an annyoning error with my pick up script. error C2248: 'UPrimitiveComponent::bGenerateOverlapEvents': cannot access private member declared in class 'UPrimitiveComponent':
I am really trying to fix this one but I cant find the fix what I need!
Here is my header code:
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Pickup.generated.h"
UCLASS()
class XAVIER_CPP_TUT_API APickup : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
APickup();
// protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaSeconds) override;
//*********************************************
UPROPERTY(EditAnywhere)
USceneComponent* PickupRoot;
//The static mesh for the pick up
UPROPERTY(EditAnywhere)
UStaticMeshComponent* PickupMesh;
UPROPERTY(EditAnywhere)
UShapeComponent* PickupBox;
UFUNCTION()
void OnPlayerEnterPickupBox(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* otherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
};
Here is my .cpp code:
// Fill out your copyright notice in the Description page of Project Settings.
#include "Pickup.h"
#include "Classes/Components/ShapeComponent.h"
#include "Classes/Components/BoxComponent.h"
#include "Components/StaticMeshComponent.h"
// Sets default values
APickup::APickup()
{
// 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;
#pragma region Declaratie_Variabelen
PickupRoot = CreateDefaultSubobject<USceneComponent>(TEXT("PickupRoot"));
RootComponent = PickupRoot;
PickupMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("PickupMesh"));
PickupMesh->AttachToComponent(PickupRoot, FAttachmentTransformRules::SnapToTargetNotIncludingScale);
// * Maak een Colliderbox -->
PickupBox = CreateDefaultSubobject<UBoxComponent>(TEXT("PickupBox"));
PickupBox->SetWorldScale3D(FVector(1.0f, 1.0f, 1.0f));
PickupBox->bGenerateOverlapEvents = true;
PickupBox->OnComponentBeginOverlap.AddDynamic(this, &APickup::OnPlayerEnterPickupBox);
PickupBox->AttachToComponent(PickupRoot, FAttachmentTransformRules::SnapToTargetNotIncludingScale);
// <-- Maak een Colliderbox *
#pragma endregion Declaratie_Variabelen
}
// Called when the game starts or when spawned
void APickup::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void APickup::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
#pragma region Custom Functions
void APickup::OnPlayerEnterPickupBox(UPrimitiveComponent * OverlappedComp, AActor * OtherActor, UPrimitiveComponent * otherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
{
Destroy();
}
#pragma endregion Custom Functions
Try PickupBox->SetGenerateOverlapEvents(true);
instead of PickupBox->bGenerateOverlapEvents = true;
https://api.unrealengine.com/INT/API/Runtime/Engine/Components/UPrimitiveComponent/index.html