2.9 KiB
2.9 KiB
title, date, excerpt, tags, rating
title | date | excerpt | tags | rating |
---|---|---|---|---|
UE4 Gameplay Debug技巧 | 2022-12-09 11:30:54 | Debug | ⭐ |
debug技巧
在release模式下开启断点的方法
如果要debug代码可以用一个非常古典的办法用
#pragma optimize("",off)
与#pragma optimize("",on)
来将一部分代码排除在优化以外
Ue4中的可视化debug法——vlog
http://api.unrealengine.com/CHN/Gameplay/Tools/VisualLogger/index.html 实现GrabDebugSnapshot接口,之后调用UE_VLOG()宏。
#if ENABLE_VISUAL_LOG
/** Appends information about this actor to the visual logger */
virtual void GrabDebugSnapshot(FVisualLogEntry* Snapshot) const override;
#endif
#if ENABLE_VISUAL_LOG
void AGDCCharacter::GrabDebugSnapshot(FVisualLogEntry* Snapshot) const
{
Super::GrabDebugSnapshot(Snapshot);
const int32 CatIndex = Snapshot->Status.AddZeroed();
FVisualLogStatusCategory& PlaceableCategory = Snapshot->Status[CatIndex];
PlaceableCategory.Category = TEXT("GDC Sample");
PlaceableCategory.Add(TEXT("Projectile Class"), ProjectileClass != nullptr ? ProjectileClass->GetName() : TEXT("None"));
}
#endif
void AGDCCharacter::OnFire()
{
// try and fire a projectile
if (ProjectileClass != NULL)
{
const FRotator SpawnRotation = GetControlRotation();
// MuzzleOffset is in camera space, so transform it to world space before offsetting from the character location to find the final muzzle position
const FVector SpawnLocation = GetActorLocation() + SpawnRotation.RotateVector(GunOffset);
UWorld* const World = GetWorld();
if (World != NULL)
{
// spawn the projectile at the muzzle
World->SpawnActor<AGDCProjectile>(ProjectileClass, SpawnLocation, SpawnRotation);
UE_VLOG(this, LogFPChar, Verbose, TEXT("Fired projectile (%s) from location (%s) with rotation (%s)"),
*ProjectileClass->GetName(),
*SpawnLocation.ToString(),
*SpawnRotation.ToString());
}
}
// try and play the sound if specified
if (FireSound != NULL)
{
UGameplayStatics::PlaySoundAtLocation(this, FireSound, GetActorLocation());
}
// try and play a firing animation if specified
if(FireAnimation != NULL)
{
// Get the animation object for the arms mesh
UAnimInstance* AnimInstance = Mesh1P->GetAnimInstance();
if(AnimInstance != NULL)
{
AnimInstance->Montage_Play(FireAnimation, 1.f);
}
}
}
之后就可以在visual logger里看到实时数据。除此之外还有一些可视的形状log:
- UE_VLOG_SEGMENT
- UE_VLOG_LOCATION
- UE_VLOG_BOX (axis aligned box)
- UE_VLOG_OBOX (oriented box)
- UE_VLOG_CONE
- UE_VLOG_CYLINDER
- UE_VLOG_CAPSULE