多人游戏调试
由于一份代码,可以同时作为服务器和客户端,因此,要使用源代码调试功能的话,应该尽量将服务器功能和客户端功能分开来调试,原则上一次只调试一边。
以下方式调试时,最好事先将Editor Preferences->Level Editor->Play->Multiplayer Options->Run Under One Process置为false,即去掉勾选。
当要调试服务器功能时:
- 通过vs按F5调试UE工程,待打开工程编辑器后,Play按钮的下拉菜单里设置Net Mode为Play As Listen Server,Number of Players为1,然后点击Play运行服务器
- 打开对应版本的UE4引擎目录,有UE4Editor.exe文件的那个目录。在该目录下打开console,执行UE4Editor.exe "%GameDir%ProjectName.uproject" 127.0.0.1 -game即可开启一个client并连接到运行的Server。当然也可以通过蓝图里执行open 127.0.0.1的console command达到同样的目的。若要client以观察者模式加入,只需传递127.0.0.1?SpectatorOnly=1作为上面的参数即可。
- 此时,vs应能收到相应的断点了
当要调试客户端功能时:
- 打开对应版本的UE4引擎目录,有UE4Editor.exe文件的那个目录。在该目录下打开console,执行UE4Editor.exe "%GameDir%ProjectName.uproject" MapName?Listen -game启动监听服务器. 或-server -log方式启动Dedecated Server
- 通过vs按F5调试UE工程,待打开工程编辑器后,Play按钮的下拉菜单里设置Net Mode为Play Standalone,Number of Players为1,然后点击Play运行客户端
- 在蓝图里通过open 127.0.0.1的console command方式可以启动连接server的工作。此时vs应能收到相应的断点了
或许还可以参考一下:Testing and Debugging Networked Games
多人网络游戏的GameMode的API调用和Event触发顺序
World.cpp >>> AGameModeBase::InitGame - C++ Actors PreInitializeComponents() AGameModeBase::PreInitializeComponents() AGameModeBase::InitGameState() - C++ World.cpp >>> AGameModeBase::PreLogin - C++ UWorld::SpawnPlayActor() AGameModeBase::Login() - C++ AGameModeBase::SpawnPlayerController() - C++ AGameModeBase::InitNewPlayer() - C++ AGameModeBase::FindPlayerStart() - C++/BP AGameModeBase::FindPlayerStart_Implementation() AGameModeBase::ChoosePlayerStart() - C++/BP SpectatorOnly!=1 ? AGameModeBase::MustSpectate() - C++/BP AGameModeBase::ChangeName() - C++ AGameModeBase::K2_OnChangeName - BP. Alias: OnChangeName AGameModeBase::PostLogin - C++。第一个可以在PlayerController上安全RPC的地方或时机。 AGameModeBase::GenericPlayerInitialization() AGameModeBase::InitializeHUDForPlayer() - C++/BP AGameModeBase::MustSpectate() - C++/BP AGameModeBase::K2_PostLogin() - BP. Alias: OnPostLogin() AGameModeBase::HandleStartingNewPlayer() - C++/BP AGameModeBase::HandleStartingNewPlayer_Implementation() AGameModeBase::MustSpectate() - 见上 AGameModeBase::PlayerCanRestart() - C++/BP AGameModeBase::RestartPlayer() - C++ AGameModeBase::FindPlayerStart() - 见上 AGameModeBase::RestartPlayerAtPlayerStart() - C++ AGameModeBase::MustSpectate() - 见上 if-else ? AGameModeBase::GetDefaultPawnClassForController() - C++/BP AGameModeBase::SpawnDefaultPawnFor() - C++/BP AGameModeBase::SpawnDefaultPawnFor_Implementation() AGameModeBase::SpawnDefaultPawnAtTransform() - C++/BP if-else ? AGameModeBase::InitStartSpot() - C++/BP if-else ? AGameModeBase::FinishRestartPlayer() - C++ if-else ? AGameModeBase::K2_OnRestartPlayer() - BP. Alias: OnRestartPlayer Controller.cpp >>> AController::Destroyed() AGameModeBase::Logout() - C++ AGameModeBase::K2_OnLogout() - BP. Alias: OnLogout UGameplayStatics::ParseOption() - 调查支持哪些参数