unreal-engine4 - 虚幻 C++ 错误:错误 C2248:“UPrimitiveComponent::bGenerateOverlapEvents”:无法访问在“UPrimitiveComponent”类中声明的私有成员
问题描述
我对 C++ 和虚幻引擎 4 非常陌生。
我正在使用盒子对撞机创建一个拾取脚本,但我的拾取脚本出现了一个错误。错误 C2248:“UPrimitiveComponent::bGenerateOverlapEvents”:无法访问在“UPrimitiveComponent”类中声明的私有成员:
我真的很想解决这个问题,但我找不到我需要的解决方法!
这是我的标题代码:
// 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
推荐阅读
- javascript - 为什么这个默认参数会破坏我的递归函数?
- memory - 编译时每个程序分配多少内存/如何为程序分配更多内存?
- sharepoint - Sharepoint 在线 GraphAPI 创建请求无效的列表
- c++ - 在 Torch C++ 中创建 BoolTensor 掩码
- javascript - Javascript - 一页上有多个相同的选项卡
- c++ - 3D 中的弹丸运动:计算碰撞时间
- java - 如何使用 Selenium lib 成功点击带有 javascript 的标签?
- sql-server - T-SQL 在表中搜索 ID
- java - 确保在执行其他操作之前在屏幕上绘制 AWT Canvas
- javascript - 部分复制 JS 对象的最佳方法是什么?