《UE4游戏开发》之 《如何获取启动时,设置的启动参数》

  1. 以PS设置启动参数为例:

在这里插入图片描述
在这里插入图片描述
2. 要在游戏中获取启动参数值,需要知道启动参数,保存的位置:
2.1 需要了解【Engine\Source\Runtime\Core\Public\Misc\CommandLine.h】

/** 
	 * Returns an edited version of the executable's command line
	 *  with the game name and certain other parameters removed
	 * 获取启动参数字符串. 
	 */
	static const TCHAR* Get();
	/**
	 * Parses a string into tokens, separating switches (beginning with -) from
	 * other parameters
	 * 解析命令字符串
	 *
	 * @param	CmdLine		the string to parse
	 * @param	Tokens		[out] filled with all parameters found in the string
	 * @param	Switches	[out] filled with all switches found in the string
	 */
	static void Parse(const TCHAR* CmdLine, TArray<FString>& Tokens, TArray<FString>& Switches);
  1. 使用方式
	TArray<FString> Tokens;
	TArray<FString> Switches;
	FCommandLine::Parse(FCommandLine::Get(), Tokens, Switches);

只需要解析Switches的字符串就可以获取,key与Value;在这里key:Dev,Value:PS4测试服;具体如何使用,由游戏决定

  1. 如何调试启动参数的获取?
    方法1: 先在ue4eidtor 【Play】->【Advanced Setting】在这里插入图片描述在Play in Standalone Game中设置启动参数
    在这里插入图片描述;然后独立窗口启动在这里插入图片描述;最后通过vs附加进程,即可调试
    在这里插入图片描述
    实际结果在这里插入图片描述
    方法2:先cook,然后修改【Configuration】为Development,并且添加【Command Arguments】在这里插入图片描述最后直接vs启动,即可调试【建议使用本方法】
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值