【问题标题】:How to fix the UClass has no member "WeaponMesh" error?如何修复 UClass 没有成员“WeaponMesh”错误?
【发布时间】:2021-03-20 12:08:45
【问题描述】:

目前我有一个适合我的角色的课程,如下所示:

.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;


};

请注意武器类型。 该武器是从我的武器的自定义通用类派生的自定义蓝图类,如下所示:

.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;

};

现在我有另一个类,它将在我的武器骨架网格的插槽中放置一个跟踪器,以便稍后跟踪它的运动。我正在尝试通过该蓝图类调用该网格,如下所示:

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");
}

请注意,我在这个类中的 Weapon 变量是 USkeletalMeshComponent 类型,它与 Weapon_Base 类中的 WeaponMesh 相同。但是当我调用网格时,我得到错误 UClass 没有成员“WeaponMesh”。我该如何解决?

感谢您的帮助!

【问题讨论】:

  • 我在您的代码中看到“WeaponMesh”的唯一情况是一次作为参数的标识符,一次是在没有上下文的 if 中尝试使用它时。这有帮助吗?如果没有,请提供minimal reproducible example
  • 嗨@Yunnosch。是的,这似乎是正确的。这就是为什么我不确定可能导致错误的原因。
  • 您回复了我的评论,但没有编辑您的问题。请允许我重复一遍:请提供minimal reproducible example

标签: c++ game-engine unreal-engine4 unreal-gameplay-ability-system


【解决方案1】:

您的武器是受保护的价值。 受保护的成员可以在定义它们的类和从该类继承的类中访问。 我不知道在哪里 调用了Weapon = Player-&gt;Weapon-&gt;WeaponMesh; //error occurs here under WeaponMesh,但是好像报错了。

尝试将您的 Weapon 值公开或使用 getter 函数。

【讨论】:

    【解决方案2】:

    对于任何将要寻找未来答案的人,我已经找到了答案。本质上,问题在于我指向的是班级而不是我产生的演员。所以我所做的就是向角色添加另一个名为武器指针的变量,并将武器保存在其中,然后我用它来调用该武器的网格。

    【讨论】:

      猜你喜欢
      • 2020-03-27
      • 2018-08-02
      • 1970-01-01
      • 2017-12-09
      • 2020-04-25
      • 2014-09-23
      • 1970-01-01
      • 2019-08-18
      • 2021-08-09
      相关资源
      最近更新 更多