如何修复 UClass has no member "WeaponMesh" 错误?
How to fix the UClass has no member "WeaponMesh" error?
目前我有一个 class 我的角色是这样的:
.h
#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "DarkFantasies_MainCharacter_Base.generated.h"
class USpringArmComponent;
class UCameraComponent;
class ADarkFantasies_WeaponBase;
UCLASS()
class PROJECT_DF_API ADarkFantasies_MainCharacter_Base : public ACharacter
{
GENERATED_BODY()
public:
ADarkFantasies_MainCharacter_Base();
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Camera")
USpringArmComponent* SpringArmCom;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Camera")
UCameraComponent* CameraCom;
protected:
virtual void BeginPlay() override;
protected:
void MoveForward(float Value);
void MoveRight(float Value);
void TurnAtRate(float Value);
void LookUpAtRate(float Value);
void InteractPressed();
void LAttackPressed();
void HAttackPressed();
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Camera")
float BaseTurnRate;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Camera")
float BaseLookUpAtRate;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Interaction")
float TraceDistance;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Animations")
UAnimMontage* M_LightAttack;
UFUNCTION(BlueprintNativeEvent)
void TraceForward();
void TraceForward_Implementation();
public:
virtual void Tick(float DeltaTime) override;
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon")
TSubclassOf<ADarkFantasies_WeaponBase> Weapon;
private:
AActor* FocusedActor;
};
请注意武器类型。
该武器是自定义蓝图 class 派生自自定义将军 class 我的武器看起来像这样:
.h
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "DarkFantasies_WeaponBase.generated.h"
UCLASS()
class PROJECT_DF_API ADarkFantasies_WeaponBase : public AActor
{
GENERATED_BODY()
public:
ADarkFantasies_WeaponBase();
protected:
virtual void BeginPlay() override;
public:
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Attributes")
float BaseDamage;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Attributes")
float AttackSpeed;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Mesh")
USkeletalMeshComponent* WeaponMesh;
};
现在我有另一个 class,它会将跟踪器放入我的武器骨架网格物体的插槽中,以便稍后跟踪它的移动。我正在尝试通过该蓝图 class 调用该网格,如下所示:
Player = Cast<ADarkFantasies_MainCharacter_Base>(MeshComp->GetOwner());
if(Player)
{
Weapon = Player->Weapon->WeaponMesh; //error occurs here under WeaponMesh
ActorsToIgnore = { MeshComp->GetOwner() };
LastLocation1 = Weapon->GetSocketLocation("Trace1");
LastLocation2 = Weapon->GetSocketLocation("Trace2");
LastLocation3 = Weapon->GetSocketLocation("Trace3");
LastLocation4 = Weapon->GetSocketLocation("Trace4");
}
请注意,我在 class 中的 Weapon 变量是 USkeletalMeshComponent 类型,它与 Weapon_Base class 中的 WeaponMesh 相同。但是当我调用网格时,出现错误 UClass 没有成员“WeaponMesh”。我该如何解决?
感谢您的帮助!
你的武器是受保护的价值。
受保护的成员可以在定义它们的 class 和从 class 继承的 class 中访问。
我不知道在哪里
调用了Weapon = Player->Weapon->WeaponMesh; //error occurs here under WeaponMesh
,但好像出错了
尝试将你的武器值设置为 public 或设置 getter 函数。
对于未来会寻找答案的任何人,我已经找到了答案。本质上,问题是我指向 class 而不是我生成的演员。所以我所做的是我向角色添加了另一个名为武器指针的变量并将武器保存在那里,然后我用它来调用正是该武器的网格。
目前我有一个 class 我的角色是这样的:
.h
#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "DarkFantasies_MainCharacter_Base.generated.h"
class USpringArmComponent;
class UCameraComponent;
class ADarkFantasies_WeaponBase;
UCLASS()
class PROJECT_DF_API ADarkFantasies_MainCharacter_Base : public ACharacter
{
GENERATED_BODY()
public:
ADarkFantasies_MainCharacter_Base();
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Camera")
USpringArmComponent* SpringArmCom;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Camera")
UCameraComponent* CameraCom;
protected:
virtual void BeginPlay() override;
protected:
void MoveForward(float Value);
void MoveRight(float Value);
void TurnAtRate(float Value);
void LookUpAtRate(float Value);
void InteractPressed();
void LAttackPressed();
void HAttackPressed();
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Camera")
float BaseTurnRate;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Camera")
float BaseLookUpAtRate;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Interaction")
float TraceDistance;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Animations")
UAnimMontage* M_LightAttack;
UFUNCTION(BlueprintNativeEvent)
void TraceForward();
void TraceForward_Implementation();
public:
virtual void Tick(float DeltaTime) override;
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon")
TSubclassOf<ADarkFantasies_WeaponBase> Weapon;
private:
AActor* FocusedActor;
};
请注意武器类型。 该武器是自定义蓝图 class 派生自自定义将军 class 我的武器看起来像这样:
.h
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "DarkFantasies_WeaponBase.generated.h"
UCLASS()
class PROJECT_DF_API ADarkFantasies_WeaponBase : public AActor
{
GENERATED_BODY()
public:
ADarkFantasies_WeaponBase();
protected:
virtual void BeginPlay() override;
public:
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Attributes")
float BaseDamage;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Attributes")
float AttackSpeed;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Mesh")
USkeletalMeshComponent* WeaponMesh;
};
现在我有另一个 class,它会将跟踪器放入我的武器骨架网格物体的插槽中,以便稍后跟踪它的移动。我正在尝试通过该蓝图 class 调用该网格,如下所示:
Player = Cast<ADarkFantasies_MainCharacter_Base>(MeshComp->GetOwner());
if(Player)
{
Weapon = Player->Weapon->WeaponMesh; //error occurs here under WeaponMesh
ActorsToIgnore = { MeshComp->GetOwner() };
LastLocation1 = Weapon->GetSocketLocation("Trace1");
LastLocation2 = Weapon->GetSocketLocation("Trace2");
LastLocation3 = Weapon->GetSocketLocation("Trace3");
LastLocation4 = Weapon->GetSocketLocation("Trace4");
}
请注意,我在 class 中的 Weapon 变量是 USkeletalMeshComponent 类型,它与 Weapon_Base class 中的 WeaponMesh 相同。但是当我调用网格时,出现错误 UClass 没有成员“WeaponMesh”。我该如何解决?
感谢您的帮助!
你的武器是受保护的价值。
受保护的成员可以在定义它们的 class 和从 class 继承的 class 中访问。
我不知道在哪里
调用了Weapon = Player->Weapon->WeaponMesh; //error occurs here under WeaponMesh
,但好像出错了
尝试将你的武器值设置为 public 或设置 getter 函数。
对于未来会寻找答案的任何人,我已经找到了答案。本质上,问题是我指向 class 而不是我生成的演员。所以我所做的是我向角色添加了另一个名为武器指针的变量并将武器保存在那里,然后我用它来调用正是该武器的网格。