Unreal C++ Error: error C2248: 'UPrimitiveComponent::bGenerateOverlapEvents': cannot access private member declared in class 'UPrimitiveComponent'
Unreal C++ Error: error C2248: 'UPrimitiveComponent::bGenerateOverlapEvents': cannot access private member declared in class 'UPrimitiveComponent'
我对 C++ 和 Unreal Engine 4.
很陌生
我正在创建一个带有盒子碰撞器的拾取脚本,但我的拾取脚本出现了一个错误。 error C2248: 'UPrimitiveComponent::bGenerateOverlapEvents': 无法访问在 class 'UPrimitiveComponent':
中声明的私有成员
我真的很想修复这个问题,但找不到我需要的修复方法!
这是我的 header 代码:
// 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);
};
这是我的 .cpp 代码:
// 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
尝试 PickupBox->SetGenerateOverlapEvents(true);
而不是 PickupBox->bGenerateOverlapEvents = true;
https://api.unrealengine.com/INT/API/Runtime/Engine/Components/UPrimitiveComponent/index.html
我对 C++ 和 Unreal Engine 4.
很陌生我正在创建一个带有盒子碰撞器的拾取脚本,但我的拾取脚本出现了一个错误。 error C2248: 'UPrimitiveComponent::bGenerateOverlapEvents': 无法访问在 class 'UPrimitiveComponent':
中声明的私有成员我真的很想修复这个问题,但找不到我需要的修复方法!
这是我的 header 代码:
// 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);
};
这是我的 .cpp 代码:
// 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
尝试 PickupBox->SetGenerateOverlapEvents(true);
而不是 PickupBox->bGenerateOverlapEvents = true;
https://api.unrealengine.com/INT/API/Runtime/Engine/Components/UPrimitiveComponent/index.html