[程式] UE4 批次执行Console commands

楼主: yekdniw (yekdniw)   2021-03-06 15:57:54
网页版
https://yekdniwue.blogspot.com/2021/03/BatchConsoleCmd.html
有的时候我们会想要执行一连串的console command,才能得到结果,
可是又不想要为这一串console command,
专门写一个console command把他们集合起来。怎么办?
作法(只需要做一次)
把功能加在CheatManager
在你继承的CheatManager.h加上函式
UFUNCTION(exec)
void ExecComboCommand(const FString& ComboCommandName);
在你继承的CheatManager.cpp实作函式
void UMyCheatManager::ExecComboCommand
(const FString& ComboCommandName)
{
FConfigSection* CommandsToRun =
GConfig->GetSectionPrivate
(*ComboCommandName, false, true, GGameIni);
if (!CommandsToRun)
{
return;
}
if (!IsValid(GetOuterAPlayerController()))
{
return;
}
for (FConfigSectionMap::TIterator It(*CommandsToRun); It; ++It)
{
GetOuterAPlayerController()->
ConsoleCommand(*It.Value().GetValue());
}
}
使用组合指令
在ini里面制作要批次执行的指令,例如在
[Project]\Saved\Config\Windows\Game.ini
新增
[Debug.ComboCommand1]
+Cmds=stat fps
+Cmds=stat unit
(新增的时候请先关闭Editor,以免修改被Editor盖掉)
如果要上平台也能测试,可能就要新增在
[Project]\Config\DefaultGame.ini
内不过记得最后要拔掉。
然后打开你的Editor或是执行目标平台的游戏,先输入
EnableCheats
再输入
ExecComboCommand Debug.ComboCommand1
就成功了
优点
不用再记各个详细的指令怎么打,只要记别名就好
有很多的command不用一直重复输入
不用怕指令忘记,因为ini会记得(除非删掉)
靠字串组合,所以程式码只要写一次(一个函式),就能支援多种指令
ComboCommand1,ComboCommand2, ...
缺点
还是要执行EnableCheats
因为靠CheatManager,所以应该只能在Game中执行,
编辑模式不确定是否有效。
为了开发方便可能会想要记在
[Project]\Config\DefaultGame.ini
,最后要记得拔掉。
作者: metallican (钢铁人)   2021-03-06 16:38:00
专业推 感谢分享
作者: coolrobin (泳圈)   2021-03-06 18:14:00

Links booklink

Contact Us: admin [ a t ] ucptt.com