Init
This commit is contained in:
74
03-UnrealEngine/Gameplay/Debug/UE4 Gameplay Debug技巧.md
Normal file
74
03-UnrealEngine/Gameplay/Debug/UE4 Gameplay Debug技巧.md
Normal file
@@ -0,0 +1,74 @@
|
||||
---
|
||||
title: UE4 Gameplay Debug技巧
|
||||
date: 2022-12-09 11:30:54
|
||||
excerpt: Debug
|
||||
tags:
|
||||
rating: ⭐
|
||||
---
|
||||
## 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()宏。
|
||||
```c++
|
||||
#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:
|
||||
1. UE_VLOG_SEGMENT
|
||||
2. UE_VLOG_LOCATION
|
||||
3. UE_VLOG_BOX (axis aligned box)
|
||||
4. UE_VLOG_OBOX (oriented box)
|
||||
5. UE_VLOG_CONE
|
||||
6. UE_VLOG_CYLINDER
|
||||
7. UE_VLOG_CAPSULE
|
166
03-UnrealEngine/Gameplay/Debug/UE_Log.md
Normal file
166
03-UnrealEngine/Gameplay/Debug/UE_Log.md
Normal file
@@ -0,0 +1,166 @@
|
||||
---
|
||||
title: UE_Log
|
||||
date: 2022-08-31 09:40:26
|
||||
excerpt:
|
||||
tags:
|
||||
rating: ⭐
|
||||
---
|
||||
说明:本文为Wiki上的RAMA大神文章的大致翻译
|
||||
|
||||
## 显示日志
|
||||
- 在游戏模式下,你需要在游戏的快捷方式后面加 -Log,才会在游戏中显示。
|
||||
- 如果想在游戏中看到,需要到Engin.ini中修改参数添加"GameCommandLine=-log,如果没有,则需要按~,输入-Log命令开启。
|
||||
|
||||
## QuickStart
|
||||
UE_LOG(LogTemp, Warning, TEXT("Your message"));
|
||||
|
||||
不用设置标签,简单快速。
|
||||
|
||||
## CustomTag
|
||||
在你的游戏头文件中进行声明:
|
||||
```c++
|
||||
//General Log
|
||||
DECLARE_LOG_CATEGORY_EXTERN(YourLog, Log, All);
|
||||
|
||||
//Logging during game startup
|
||||
DECLARE_LOG_CATEGORY_EXTERN(YourInit, Log, All);
|
||||
|
||||
//Logging for your AI system
|
||||
DECLARE_LOG_CATEGORY_EXTERN(YourAI, Log, All);
|
||||
|
||||
//Logging for Critical Errors that must always be addressed
|
||||
DECLARE_LOG_CATEGORY_EXTERN(YourCriticalErrors, Log, All);
|
||||
```
|
||||
这样输出的Log你就可以知道是哪个部分的,这也是UE_Log很有用的原因。
|
||||
|
||||
之后在你的游戏Cpp文件中定义:
|
||||
```c++
|
||||
//General Log
|
||||
DEFINE_LOG_CATEGORY(YourLog);
|
||||
|
||||
//Logging during game startup
|
||||
DEFINE_LOG_CATEGORY(YourInit);
|
||||
|
||||
//Logging for your AI system
|
||||
DEFINE_LOG_CATEGORY(YourAI);
|
||||
|
||||
//Logging for Critical Errors that must always be addressed
|
||||
DEFINE_LOG_CATEGORY(YourCriticalErrors);
|
||||
```
|
||||
|
||||
## Log格式化
|
||||
### Log Message
|
||||
```c++
|
||||
//"This is a message to yourself during runtime!"
|
||||
UE_LOG(YourLog,Warning,TEXT("This is a message to yourself during runtime!"));
|
||||
```
|
||||
|
||||
### Log an FString
|
||||
```c++
|
||||
%s strings are wanted as TCHAR* by Log, so use *FString()
|
||||
//"MyCharacter's Name is %s"
|
||||
UE_LOG(YourLog,Warning,TEXT("MyCharacter's Name is %s"), *MyCharacter->GetName() );
|
||||
```
|
||||
|
||||
### Log an Int
|
||||
```c++
|
||||
//"MyCharacter's Health is %d"
|
||||
UE_LOG(YourLog,Warning,TEXT("MyCharacter's Health is %d"), MyCharacter->Health );
|
||||
```
|
||||
|
||||
### Log a Float
|
||||
```c++
|
||||
//"MyCharacter's Health is %f"
|
||||
UE_LOG(YourLog,Warning,TEXT("MyCharacter's Health is %f"), MyCharacter->Health );
|
||||
```
|
||||
|
||||
### Log an FVector
|
||||
```c++
|
||||
//"MyCharacter's Location is %s"
|
||||
UE_LOG(YourLog,Warning,TEXT("MyCharacter's Location is %s"),
|
||||
*MyCharacter->GetActorLocation().ToString());
|
||||
```
|
||||
|
||||
### Log an FName
|
||||
```c++
|
||||
//"MyCharacter's FName is %s"
|
||||
UE_LOG(YourLog,Warning,TEXT("MyCharacter's FName is %s"),
|
||||
*MyCharacter->GetFName().ToString());
|
||||
```
|
||||
|
||||
### Log an FString,Int,Float
|
||||
```c++
|
||||
//"%s has health %d, which is %f percent of total health"
|
||||
UE_LOG(YourLog,Warning,TEXT("%s has health %d, which is %f percent of total health"),
|
||||
*MyCharacter->GetName(), MyCharacter->Health, MyCharacter->HealthPercent);
|
||||
```
|
||||
|
||||
## Log的颜色设置
|
||||
```c++
|
||||
//"this is Grey Text"
|
||||
UE_LOG(YourLog,Log,TEXT("This is grey text!"));
|
||||
|
||||
//"this is Yellow Text"
|
||||
UE_LOG(YourLog,Warning,TEXT("This is yellow text!"));
|
||||
|
||||
//"This is Red Text"
|
||||
UE_LOG(YourLog,Error,TEXT("This is red text!"));
|
||||
```
|
||||
|
||||
可以看得出第二个参数是是用来控制颜色的。
|
||||
|
||||
## 向客户端传递信息(网络模式):
|
||||
```c++
|
||||
PlayerController->ClientMessage("Your Message");
|
||||
```
|
||||
|
||||
命令行命令以及Engine.ini配置:
|
||||
Log conventions (in the console, ini files, or environment variables)
|
||||
|
||||
[cat] = a category for the command to operate on, or 'global' for all categories.
|
||||
标签,没有设置就显示所有的Log
|
||||
|
||||
[level] = verbosity level, one of: none, error, warning, display, log, verbose, all, default
|
||||
关卡,显示某某关卡的Log
|
||||
|
||||
At boot time, compiled in default is overridden by ini files setting, which is overridden by command line
|
||||
|
||||
Log console command usage
|
||||
|
||||
Log list - list all log categories
|
||||
|
||||
Log list [string] - list all log categories containing a substring
|
||||
|
||||
Log reset - reset all log categories to their boot-time default
|
||||
|
||||
Log [cat] - toggle the display of the category [cat]
|
||||
|
||||
Log [cat] off - disable display of the category [cat]
|
||||
|
||||
Log [cat] on - resume display of the category [cat]
|
||||
|
||||
Log [cat] [level] - set the verbosity level of the category [cat]
|
||||
|
||||
Log [cat] break - toggle the debug break on display of the category [cat]
|
||||
|
||||
### Log command line
|
||||
- LogCmds=\"[arguments],[arguments]...\" - applies a list of console commands at boot time
|
||||
- LogCmds=\"foo verbose, bar off\" - turns on the foo category and turns off the bar category
|
||||
|
||||
### Environment variables
|
||||
Any command line option can be set via the environment variable UE-CmdLineArgs
|
||||
|
||||
set UE-CmdLineArgs=\"-LogCmds=foo verbose breakon, bar off\"
|
||||
|
||||
### Config file
|
||||
In DefaultEngine.ini or Engine.ini:
|
||||
```ini
|
||||
[Core.Log]
|
||||
global=[default verbosity for things not listed later]
|
||||
[cat]=[level]
|
||||
foo=verbose break
|
||||
```
|
||||
|
||||
## 其他
|
||||
Rama后面的一篇文章提供了显示代码行号、函数名称、类名等功能:
|
||||
https://wiki.unrealengine.com/Logs,_Printing_the_Class_Name,_Function_Name,_Line_Number_of_your_Calling_Code!
|
54
03-UnrealEngine/Gameplay/Debug/打包项目的Debug方法.md
Normal file
54
03-UnrealEngine/Gameplay/Debug/打包项目的Debug方法.md
Normal file
@@ -0,0 +1,54 @@
|
||||
---
|
||||
title: 打包项目的Debug方法
|
||||
date: 2022-08-24 13:30:08
|
||||
excerpt:
|
||||
tags: debug
|
||||
rating: ⭐
|
||||
---
|
||||
## 参考视频
|
||||
https://www.youtube.com/watch?v=CmWbMT4WAhU
|
||||
|
||||
## Shipping模式保存日志文件
|
||||
1. 在您的 {projectname}.Target.cs 文件的 contrsutor 中,添加以下行: `bUseLoggingInShipping = true;`。
|
||||
2. 根据源码版与官方编译版有额外的2个设置:
|
||||
1. 源码版:增加`BuildEnvironment = TargetBuildEnvironment.Unique`。
|
||||
2. 官方编译版:增加`bOverrideBuildEnvironment = true;`。
|
||||
|
||||
比如:
|
||||
```c#
|
||||
public class GameTarget : TargetRules
|
||||
{
|
||||
public GameTarget(TargetInfo Target) : base(Target)
|
||||
{
|
||||
Type = TargetType.Game;
|
||||
|
||||
// enable logs and debugging for Shipping builds
|
||||
if (Configuration == UnrealTargetConfiguration.Shipping)
|
||||
{
|
||||
BuildEnvironment = TargetBuildEnvironment.Unique;
|
||||
bUseChecksInShipping = true;
|
||||
bUseLoggingInShipping = true;
|
||||
}
|
||||
|
||||
ExtraModuleNames.AddRange( new string[] { "Game" } );
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
## Debug打包后的游戏
|
||||
1. 以DebugGame模式进行打包。
|
||||
2. 运行游戏,并在任务管理器中找到该游戏进程。
|
||||
3. 右键选择调试。
|
||||
|
||||
或者可以在VS里手动选择附加进程。
|
||||
|
||||
## 调试相关命令行
|
||||
1. 如果想在一开始就进行附加,可以在游戏运行方式中加入`-waitforattach`。
|
||||
2. 在游戏运行方式中加入`-log`就可以在开始时显示log。
|
||||
|
||||
## 生成调试符号
|
||||
**Settings -> Packaging Settings -> Project**中勾选Include Debug Files选项就可以生成PDB文件。
|
||||
|
||||
## UE4Launcher
|
||||
查里鹏开发的工具,可以方便启动UE工程:https://github.com/hxhb/UE4Launcher
|
Reference in New Issue
Block a user