c++ - fatal error LNK2019 C++,Unreal Engine Build

当我尝试为 Unreal Engine 4.26 构建我的 cpp 代码时出现错误。我尝试添加到我的游戏功能中以确定我玩游戏时的表面类型。这就是我添加 UDeterminSurfaceType 函数的原因。部分代码如下所示:

SurfaceType = UPhysicalMaterial::DetermineSurfaceType(Hit.PhysMaterial.Get());

        UParticleSystem* SelectedEffect = nullptr;
        switch (SurfaceType)
        {
        case SurfaceType1:
            SelectedEffect = FleshImpactEffect;
            break;
        case SurfaceType2:
            SelectedEffect = FleshImpactEffect;
            break;
        default:
            SelectedEffect = DefaultImpactEffect;
            break;
        }


        if (SelectedEffect)
        {
            UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), SelectedEffect, Hit.ImpactPoint,
        Hit.ImpactNormal.Rotation());
        }

我知道事实还没有打磨,以后再做。添加此行并构建项目后,出现 LNK2019 错误。

  Error LNK2019 unresolved external symbol "__declspec(dllimport) public: static enum 
  EPhysicalSurface __cdecl UPhysicalMaterial::DetermineSurfaceType(class UPhysicalMaterial const *)" 
  (__imp_?DetermineSurfaceType@UPhysicalMaterial@@SA?AW4EPhysicalSurface@@PEBV1@@Z) referenced in 
  function "public: virtual void __cdecl ASWeapon::Fire(void)" (?Fire@ASWeapon@@UEAAXXZ)

这个错误意味着,我的 ASWeapon 类头文件中有一个名为“Fire”的方法,但它不存在于您的 SWeapon.CPP 文件中。因此,链接器为您的武器类创建了一个 OBJ 文件,然后当它尝试将声明与实现相匹配时,它找不到实现并且您得到了这个可爱的链接器错误。但是我在 CPP 和头文件中已经有了方法“Fire”。它是在这里创建的:

public: 

UFUNCTION(BlueprintCallable, Category = "Weapon")
virtual void Fire();

这是完整的 SWeapon.cpp 代码:

static int32 DebugWeaponsDrawing = 0;
FAutoConsoleVariableRef CVARDebugWeaponDrawing(
TEXT("COOP.DebugWeapons"), 
DebugWeaponsDrawing, 
TEXT("Draw Debug Lines for Weapons"), 
ECVF_Cheat);

// Sets default values
ASWeapon::ASWeapon()
{
MeshComp = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("MeshComp"));
RootComponent = MeshComp;

MuzzleSocketName = "MuzzleSocket";
TracerTargetName = "Target";
}


void ASWeapon::Fire()
{
// urmarirea mapei din ochii pionului pana la locatia tintei

AActor* MyOwner = GetOwner();
if (MyOwner)
{
    FVector EyeLocation;
    FRotator EyeRotation;
    MyOwner->GetActorEyesViewPoint(EyeLocation, EyeRotation);

    FVector ShotDirection = EyeRotation.Vector();

    FVector TraceEnd = EyeLocation + (ShotDirection * 10000);

    FCollisionQueryParams QueryParams;
    QueryParams.AddIgnoredActor(MyOwner);
    QueryParams.AddIgnoredActor(this);
    QueryParams.bTraceComplex = true;

    // parametrul pentru particulele tintei
    FVector TracerEndPoint = TraceEnd;

    EPhysicalSurface SurfaceType = SurfaceType_Default;

    FHitResult Hit;
    if (GetWorld()->LineTraceSingleByChannel(Hit, EyeLocation, TraceEnd, ECC_Visibility, 
    QueryParams))
    {
        // Blocare lovitura, cauzeaza daune

        AActor* HitActor = Hit.GetActor();

        UGameplayStatics::ApplyPointDamage(HitActor, 20.0f, ShotDirection, Hit, MyOwner- 
        >GetInstigatorController(), this, DamageType);

        SurfaceType = UPhysicalMaterial::DetermineSurfaceType(Hit.PhysMaterial.Get());

        UParticleSystem* SelectedEffect = nullptr;
        switch (SurfaceType)
        {
        case SurfaceType1:
            SelectedEffect = FleshImpactEffect;
            break;
        case SurfaceType2:
            SelectedEffect = FleshImpactEffect;
            break;
        default:
            SelectedEffect = DefaultImpactEffect;
            break;
        }


        if (SelectedEffect)
        {
            UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), SelectedEffect, Hit.ImpactPoint, 
        Hit.ImpactNormal.Rotation());
        }

        TracerEndPoint = Hit.ImpactPoint;

    }

    if (DebugWeaponsDrawing > 0)
    {
        DrawDebugLine(GetWorld(), EyeLocation, TraceEnd, FColor::White, false, 1.0f, 0, 1.0f);
    }

    PlayFireEffects(TracerEndPoint);
}

}


void ASWeapon::PlayFireEffects(FVector TraceEnd)
{
if (MuzzleEffect)
{
    UGameplayStatics::SpawnEmitterAttached(MuzzleEffect, MeshComp, MuzzleSocketName);
}

if (TracerEffect)
{
    FVector MuzzleLocation = MeshComp->GetSocketLocation(MuzzleSocketName);

    UParticleSystemComponent* TracerComp = UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), TracerEffect, MuzzleLocation);
    if (TracerComp)
    {
        TracerComp->SetVectorParameter(TracerTargetName, TraceEnd);
    }

}

APawn* MyOwner = Cast<APawn>(GetOwner());
if (MyOwner)
{
    APlayerController* PC = Cast<APlayerController>(MyOwner->GetController());
    if (PC)
    {
        PC->ClientPlayCameraShake(FireCamShake);
    }
}
}

这是标题代码:

class USkeletalMeshComponent;
class UDamageType;
class UParticleSystem;

UCLASS()
class GAME_API ASWeapon : public AActor
{
GENERATED_BODY()

public: 
// Sets default values for this actor's properties
ASWeapon();

protected:

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components")
USkeletalMeshComponent* MeshComp;

void PlayFireEffects(FVector TraceEnd);

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Weapon")
TSubclassOf<UDamageType> DamageType;

UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "Weapon")
FName MuzzleSocketName;

UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "Weapon")
FName TracerTargetName;

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Weapon")
UParticleSystem* MuzzleEffect;

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Weapon")
UParticleSystem* DefaultImpactEffect;

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Weapon")
UParticleSystem* FleshImpactEffect;

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Weapon")
UParticleSystem* TracerEffect;

UPROPERTY(EditDefaultsOnly, Category = "Weapon")
TSubclassOf<UCameraShakeBase> FireCamShake;


public: 

UFUNCTION(BlueprintCallable, Category = "Weapon")
virtual void Fire();
};

在添加表面类型检测器之前,其余代码工作得很好。如果您知道如何解决这个问题,我将不胜感激。

最佳答案

我发现了问题。在 UE4.26 中,为 Physic Core 添加了一个新功能作为模块依赖项。我必须将这个核心添加到 Game(your game name).build.cs 中。 那是一行:

PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", 
"InputCore", "PhysicsCore" });

关于c++ - fatal error LNK2019 C++,Unreal Engine Build,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65634298/

相关文章:

c++ - C++ 是否包含包含的头文件包含的所有头文件?

powershell - 在 switch 语句中分配变量

python - 从明亮的彩条下发现图像

python - PyTorch 张量的零对角线?

javascript - JavaScript 中的常量数组

reactjs - React 项目中的 URI 格式错误 - 使用 Parcel Bundler

.htaccess - 使用 Apache 在 DDEV 中重定向 HTTP -> HTTPS

database - 如何在 Jetbrain 的 Datagrip 中以字符串 UUID 格式显示

docker - macOS Big Sur : Something always takes my

reactjs - 接口(interface)命名约定(接口(interface)名称与组件名称冲突