骨架网格体组件 Return 空 PTR(断点使用、空变量、可能变量设置不正确)

Skeletal Mesh Components Return Null PTR (Breakpoint Usage, Null Variables, Possibly Setting Variables incorrectly)

The Summary

问题是,当我尝试使用 MSVS 的本地 Windows 调试器启动引擎时,MSVS 触发了一个断点并告诉我由于某种原因骨架网格体为 NULL PTR。我不知道为什么。如果是因为我设置的变量不正确?请告诉我如何正确地做到这一点。

我编译并在编辑器中查找适当的更改,由于某种原因一切都很好,但是当我尝试使用 MSVS 打开编辑器时它触发了一个断点,表明骨架网格物体为空。请任何建议将不胜感激感谢您的时间和耐心。如果我做的一切都正确那么它可能是一个错误......我不知道。

The . H

//Here is the .h File where the variables are.
            AMainCharacter();
            UPROPERTY(EditAnywhere, Category = "EnemyWeaponBaseMesh")
            class USkeletalMeshComponent* EnemyWeaponBaseMesh;
        UPROPERTY(EditAnywhere, Category = "SkeletonRightArm ")
            class USkeletalMeshComponent* SkeletonRightArm;

The .CPP Constructor

    AMainCharacter::AMainCharacter()
    {   
        RootComponent = GetCapsuleComponent();
        GetMesh()->SetupAttachment(RootComponent);
        /*This is where the NULL PTR error starts. The debugger says that 
        EnemyWeaponBase Mesh Returns NULL.*/
        EnemyWeaponBaseMesh = CreateDefaultSubobject<USkeletalMeshComponent> 
        (TEXT("EnemyWeaponBase"));
         EnemyWeaponBaseMesh->AttachToComponent(SkeletonRightArm, 
         FAttachmentTransformRules::SnapToTargetIncludingScale, 
         FName("EnemyWeaponBase"));
        SkeletonRightArm = CreateDefaultSubobject<USkeletalMeshComponent> 
        (TEXT("RightArmSkeleton"));
        SkeletonRightArm->AttachToComponent(GetMesh(), 
        FAttachmentTransformRules::SnapToTargetIncludingScale, 
          FName("RightShoulderSocket"));     
    }

首先,ACharacter 是一个引擎 class,你不应该修改它,相反你应该有一个子class 并修改它。如果您已经对其进行了 subclass 编辑,则无需将 CapulseComponent 的附件设置为 RootComponent。它已经是 RootComponent,Mesh 也是如此。

其次,在构造函数中应该使用SetupAttachment()而不是AttachToComponent()

确保在使用之前始终检查您的指针的有效性。