视觉致命错误LNK2019 C++,Ureal引擎内部版本



我在尝试为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类头文件中,但它不存在于SWeapon.CPP文件中。因此,链接器为你的武器类创建了一个OBJ文件,然后当它试图将声明与实现匹配时,它找不到实现,你会得到这个可爱的链接器错误。但我已经有了方法"火"在CPP和头文件中。它在这里创建:

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

在添加Surface Type检测器之前,代码的其余部分工作得非常好。如果你知道如何解决这个问题,我将不胜感激。

我发现了问题。在UE4.26中,为Physic Core添加了一个新功能,作为模块依赖项。我必须把这个核心添加到Game(你的游戏名称(.build.cs中。这是一条线:

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

相关内容

  • 没有找到相关文章

最新更新