ue4-todo_list_network
记录一些有待 todo 的事项
Network 相关
- 连接服务器流程
- GameMode、GmaeState、PlayerController
- 参考:https://docs-origin.unrealengine.com/latest/INT/Gameplay/Networking/Server/index.html
启动exe加参数
- 直接创建一个快捷方式,后面添加启动参数 如 -log
常见错误
DefaultEngine.ini 没有加
1
2[OnlineSubsystem]
DefaultPlatformService=NullMyNet.Build.cs 没有加
1
2
3
4PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "HeadMountedDisplay", "OnlineSubsystem",
"OnlineSubsystemUtils" });
DynamicallyLoadedModuleNames.Add("OnlineSubsystemNull");Run Dedicated Server
- Not Checked:则可以 Create Session
- Checked:则不可以 Create Session,原因:NULL: Cannot create session ‘Game’: session already exists.
要继承GameModeBase 而不是 GameMode
api测试
- UGameplayStatics::GetIntOption
1
const int32 BotsCountOptionValue = UGameplayStatics::GetIntOption(Options, GetBotsCountOptionName(), 0);
遍历 world 中所有 APlayerStart
的派生类示例对象。(遍历指场景中的实例对象 是指 拖入 or 动态实例化出来的对象 )
1 | for (TActorIterator<APlayerStart> It(GetWorld()); It; ++It) |
reliable 和 BlueprintNativeEvent 类似都可以 _implementation??
1 | /** Starts the online game using the session name in the PlayerState */ |
shared ptr 使用
1 | class FShooterIngameMenu : public TSharedFromThis<FShooterIngameMenu> |
虚幻内部socket导入
- http://www.unrealchina.com/forum.php?mod=viewthread&tid=1837&from=portal
- https://wiki.unrealengine.com/TCP_Socket_Listener,_Receive_Binary_Data_From_an_IP/Port_Into_UE4,_(Full_Code_Sample)
引擎delegate FGameDelegates
- 参照 ShooterGameDelegates.h
网络事件触发
- 参照 ShooterPlayerController.cpp 中的 ClientGameStarted_Implementation()
bool UShooterGameInstance::LoadFrontEndMap(const FString& MapName)
1 | if (URL.Valid && !HasAnyFlags(RF_ClassDefaultObject)) //CastChecked<UEngine>() will fail if using Default__ShooterGameInstance, so make sure that we're not default |
online and session相关
- https://docs.unrealengine.com/latest/INT/Programming/Online/index.html
- https://docs.unrealengine.com/latest/INT/Engine/Blueprints/UserGuide/OnlineNodes/
- https://www.youtube.com/watch?v=so0-0dafVsE&list=PLLiI_CRDNPL-FUUPcViHe6Ypabo1ghXh3&index=1
- https://www.youtube.com/watch?v=o6DI2L_jaqA&feature=share&list=PLLiI_CRDNPL95LQnS6PGjrWxHkWbHcjAl&index=20
- 在GameInstance中添加一个字段设置标记可好?
UNetConnection 和 LocalPlayer 详解
Game Session
https://wiki.unrealengine.com/How_To_Use_Sessions_In_C%2B%2B#Known_Issues_and_workarounds
https://www.youtube.com/watch?v=abmzWUWxy1U&list=PLZlv_N0_O1gYqSlbGQVKsRg6fpxWndZqZ
https://www.youtube.com/watch?v=jSeg3zZso48&list=PLRrOfLSL-UhQgXSHmY2eH6DgvuaJKBvmo
dedicated server
复制level
- 随便新建一新level,设置编辑的level为新level,再把就的level复制一下即可
设置输入
- 在 playercontroller 中
GameplayDebugger Tool
SaveGame
从 PlayerState 索引到 AplayerController,再索引到 Acharacter
因为在 Multiplayer 中,PlayerState 中保存着客户端的玩家的信息
蓝图中获取
从 PlayerState.cpp 的源码中可以看到这样获取 APlayerController
1
2
3
4
5
6
7
8
9
10
11//step 1
AController* OwningController = Cast<AController>(GetOwner());
if (OwningController != NULL)
{
bIsABot = (Cast<APlayerController>(OwningController) == nullptr);
}
//step 2
FORCEINLINE APawn* GetPawn() const { return Pawn; }
在 Cast<ACharacter> 到你的派生类
无缝切换 seamless travel
https://docs.unrealengine.com/latest/INT/Gameplay/Networking/Travelling/
启用 seamless travel:
- 在配置文件 ./Config/DefaultEngine.ini
1
2[/Script/EngineSettings.GameMapsSettings]
TransitionMap=/Game/ThirdPersonBP/Maps/LoadingMap
- 对应源码中的 UGameMapsSettings::TransitionMap,默认为空
- 设置 AGameModeBase::bUseSeamlessTravel 为 true
- 蓝图中直接勾选
- c++ 中 在构造函数中
bUseSeamlessTravel = true
- 在配置文件 ./Config/DefaultEngine.ini
在PIE模式下不能启用 seamless travel,引擎警告:
LogGameMode:Warning: AGameModeBase::CanServerTravel: Seamless travel currently NOT supported in single process PIE.