Skip to content

Commit

Permalink
Merge pull request #65 from metaworking/ue-5.1
Browse files Browse the repository at this point in the history
Support UE 5.1
  • Loading branch information
indiest authored Sep 5, 2023
2 parents dcfd560 + 8b68640 commit c34af74
Show file tree
Hide file tree
Showing 29 changed files with 124 additions and 69 deletions.
Binary file modified Content/EditorUtilityWidgets/ChannelDataSchemaEditor.uasset
Binary file not shown.
Binary file modified Content/EditorUtilityWidgets/CloudDeployment.uasset
Binary file not shown.
Binary file modified Content/EditorUtilityWidgets/EUW_ChannelDataSchemaItem.uasset
Binary file not shown.
Binary file modified Content/EditorUtilityWidgets/EUW_EditableTextListItem.uasset
Binary file not shown.
Binary file modified Content/EditorUtilityWidgets/EUW_FilePicker.uasset
Binary file not shown.
Binary file modified Content/EditorUtilityWidgets/EUW_ServerGroup.uasset
Binary file not shown.
Binary file not shown.
Binary file modified Content/EditorUtilityWidgets/WBP_Selector_ChanneldUE.uasset
Binary file not shown.
5 changes: 4 additions & 1 deletion Docs/zh/add-replication.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@
最后,代码生成后,会自动编译。编译成功,则整个生成步骤完毕。下面可以进入游戏看看效果了。

```
注意:每次进行同步相关的修改后(包括:增删改名同步类,同步变量,或RPC)都需要重新生成同步代码。每次新增同步Actor后都需要将其状态添加至对应的频道数据模型中。
注意:
1. 请保证UE编辑器偏好中的Live Coding功能在关闭的情况下,进行代码生成,否则重新启动游戏服务器时会报错;
2. 每次进行同步相关的修改后(包括:增删改名同步类,同步变量,或RPC)都需要重新生成同步代码;
3. 每次新增同步Actor后都需要将其状态添加至对应的频道数据模型中,才能使其正常同步。
```

## 6.5.启动服务器并测试
Expand Down
5 changes: 3 additions & 2 deletions Docs/zh/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
- 如果输出日志中出现`failed to listen`的错误,说明端口被占用。请检查默认的端口12108和11288是否被其它程序占用,或者在channeld配置文件中修改端口号

## 游戏服务器启动后自动退出
- 检查channeld服务是否正常运行。在开启了channeld网络(`Enable Channeld Networking`)时,游戏服务器会尝试连接channeld服务。如果连接失败,游戏服务器会自动退出
- 检查游戏服务器的日志。日志文件通常位于项目目录下的`Saved/Logs`目录中,以项目名_{数字}命名。在单服模式下,数字为2是游戏服务器日志;在多服模式下,数字为2是主服务器日志,数字从3开始是空间服务器日志
- 检查channeld服务是否正常运行。在开启了channeld网络(`Enable Channeld Networking`)时,游戏服务器会尝试连接channeld服务。如果连接失败,游戏服务器会自动退出;
- 确认[Live Coding](https://docs.unrealengine.com/5.0/en-US/using-live-coding-to-recompile-unreal-engine-applications-at-runtime/)的设置是关闭的,否则会日志中会出现`Error: Failed to register channel data type by name`
- 如果上述方法仍无法解决,请检查游戏服务器的日志。日志文件通常位于项目目录下的`Saved/Logs`目录中,以项目名_{数字}命名。在单服模式下,数字为2是游戏服务器日志;在多服模式下,数字为2是主服务器日志,数字从3开始是空间服务器日志。

## 无法保存蓝图
如果出现“无法保存资产”的错误提示,通常是由于游戏服务器仍在运行,导致蓝图文件被占用。请先关闭游戏服务器,再保存蓝图。
Expand Down
3 changes: 1 addition & 2 deletions Source/ChanneldEditor/ChanneldEditor.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,14 @@ public ChanneldEditor(ReadOnlyTargetRules Target) : base(Target)
"EngineSettings",
"Json",
"JsonUtilities",
#if UE_5_0_OR_LATER
#if UE_5_0_OR_LATER
"DeveloperToolSettings",
"ToolMenus",
#endif
// ... add private dependencies that you statically link with here ...
}
);


DynamicallyLoadedModuleNames.AddRange(
new string[]
{
Expand Down
2 changes: 1 addition & 1 deletion Source/ChanneldEditor/ChanneldEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void FChanneldEditorModule::StartupModule()

TSharedPtr<FExtender> ToolbarExtender = MakeShareable(new FExtender());
ToolbarExtender->AddToolBarExtension("Compile", EExtensionHook::After, PluginCommands,
FToolBarExtensionDelegate::CreateRaw(this, &FChanneldEditorModule::AddToolbarButton));
FToolBarExtensionDelegate::CreateRaw(this, &FChanneldEditorModule::AddToolbarButton));
LevelEditorModule.GetToolBarExtensibilityManager()->AddExtender(ToolbarExtender);
#endif

Expand Down
33 changes: 18 additions & 15 deletions Source/ChanneldEditor/ChanneldEditorSubsystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "Misc/Base64.h"
#include "Settings/EditorExperimentalSettings.h"
#include "Settings/ProjectPackagingSettings.h"
#if ENGINE_MAJOR_VERSION >= 5
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 2
#include "Settings/PlatformsMenuSettings.h"
#endif
#include "Windows/MinWindows.h"
Expand Down Expand Up @@ -609,7 +609,7 @@ void UChanneldEditorSubsystem::BuildServerDockerImage(const FString& Tag,
return;
}

#if ENGINE_MAJOR_VERSION >= 5
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 2
const UPlatformsMenuSettings* PlatformsSettings = GetDefault<UPlatformsMenuSettings>();
FDirectoryPath StagingDirectory = PlatformsSettings->StagingDirectory;
#else
Expand Down Expand Up @@ -888,15 +888,19 @@ void UChanneldEditorSubsystem::PackageProject(const FName InPlatformInfoName,
bool bProjectHasCode = GameProjectModule.Get().ProjectHasCodeFiles();

#if ENGINE_MAJOR_VERSION >= 5
const PlatformInfo::FTargetPlatformInfo* PlatformInfo = nullptr;
if (FApp::IsInstalled())
{
PlatformInfo = PlatformInfo::FindPlatformInfo(InPlatformInfoName);
}
else
{
PlatformInfo = PlatformInfo::FindPlatformInfo(GetMutableDefault<UPlatformsMenuSettings>()->GetTargetFlavorForPlatform(InPlatformInfoName));
}
#if ENGINE_MINOR_VERSION >= 2
const PlatformInfo::FTargetPlatformInfo* PlatformInfo = nullptr;
if (FApp::IsInstalled())
{
PlatformInfo = PlatformInfo::FindPlatformInfo(InPlatformInfoName);
}
else
{
PlatformInfo = PlatformInfo::FindPlatformInfo(GetMutableDefault<UPlatformsMenuSettings>()->GetTargetFlavorForPlatform(InPlatformInfoName));
}
#else
const PlatformInfo::FTargetPlatformInfo* PlatformInfo = PlatformInfo::FindPlatformInfo(InPlatformInfoName);
#endif
#else
const PlatformInfo::FPlatformInfo* const PlatformInfo = PlatformInfo::FindPlatformInfo(InPlatformInfoName);
#endif
Expand Down Expand Up @@ -929,8 +933,7 @@ void UChanneldEditorSubsystem::PackageProject(const FName InPlatformInfoName,
// NOTE: Cannot find SDKStatus in UE5
#if ENGINE_MAJOR_VERSION < 5
if (PlatformInfo->SDKStatus == PlatformInfo::EPlatformSDKStatus::NotInstalled || (bProjectHasCode &&
PlatformInfo->
bUsesHostCompiler && !FSourceCodeNavigation::IsCompilerAvailable()))
PlatformInfo->bUsesHostCompiler && !FSourceCodeNavigation::IsCompilerAvailable()))
{
IMainFrameModule& MainFrameModule = FModuleManager::GetModuleChecked<IMainFrameModule>(TEXT("MainFrame"));
MainFrameModule.BroadcastMainFrameSDKNotInstalled(PlatformInfo->TargetPlatformName.ToString(),
Expand Down Expand Up @@ -1116,7 +1119,7 @@ void UChanneldEditorSubsystem::PackageProject(const FName InPlatformInfoName,
return;
}

#if ENGINE_MAJOR_VERSION >= 5
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 2
UPlatformsMenuSettings* PlatformsSettings = GetMutableDefault<UPlatformsMenuSettings>();
FDirectoryPath& StagingDirectory = PlatformsSettings->StagingDirectory;
#else
Expand Down Expand Up @@ -1148,7 +1151,7 @@ void UChanneldEditorSubsystem::PackageProject(const FName InPlatformInfoName,
}

StagingDirectory.Path = OutFolderName;
#if ENGINE_MAJOR_VERSION >= 5
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 2
PlatformsSettings->SaveConfig();
#else
PackagingSettings->SaveConfig();
Expand Down
33 changes: 21 additions & 12 deletions Source/ChanneldEditor/ClientInterestSettingsCustomization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include "SlateBasics.h"
#include "DetailWidgetRow.h"
#include "DetailLayoutBuilder.h"
#if ENGINE_MAJOR_VERSION >= 5
#include "EditorStyleSet.h"
#endif
#include "IDetailChildrenBuilder.h"


Expand Down Expand Up @@ -39,8 +42,13 @@ void FClientInterestSettingsCustomization::CustomizeHeader(TSharedRef<IPropertyH
.AutoWidth()
[
SNew(STextBlock)
.Font(FEditorStyle::GetFontStyle("PropertyWindow.NormalFont"))
.Text(FText::Format(LOCTEXT("ClientInterestSettingsAreaTypeString", "The area type is \"{0}\""), AreaTypeText))
#if ENGINE_MAJOR_VERSION >= 5
.Font(FAppStyle::GetFontStyle("PropertyWindow.NormalFont"))
#else
.Font(FEditorStyle::GetFontStyle("PropertyWindow.NormalFont"))
#endif

.Text(FText::Format(LOCTEXT("ClientInterestSettingsAreaTypeString", "The area type is \"{0}\""), AreaTypeText))
]
];
}
Expand All @@ -57,7 +65,8 @@ void FClientInterestSettingsCustomization::OnTypeChanged(TSharedPtr<IPropertyHan
}

void FClientInterestSettingsCustomization::CustomizeChildren(TSharedRef<IPropertyHandle> StructPropertyHandle,
IDetailChildrenBuilder& StructBuilder, IPropertyTypeCustomizationUtils& StructCustomizationUtils)
IDetailChildrenBuilder& StructBuilder,
IPropertyTypeCustomizationUtils& StructCustomizationUtils)
{
auto TypePropertyHandle = StructPropertyHandle->GetChildHandle(GET_MEMBER_NAME_CHECKED(FClientInterestSettingsPreset, AreaType));
auto SpotsPropertyHandle = StructPropertyHandle->GetChildHandle(GET_MEMBER_NAME_CHECKED(FClientInterestSettingsPreset, SpotsAndDists));
Expand All @@ -84,7 +93,7 @@ void FClientInterestSettingsCustomization::CustomizeChildren(TSharedRef<IPropert
[
TypePropertyHandle->CreatePropertyNameWidget()
]
+SVerticalBox::Slot()
+ SVerticalBox::Slot()
.AutoHeight()
[
TypePropertyHandle->CreatePropertyValueWidget()
Expand All @@ -94,7 +103,7 @@ void FClientInterestSettingsCustomization::CustomizeChildren(TSharedRef<IPropert
.Padding(5, 0)
[
SNew(SBox)
.IsEnabled_Lambda([=] {return AreaType == EClientInterestAreaType::StaticLocations; })
.IsEnabled_Lambda([=] { return AreaType == EClientInterestAreaType::StaticLocations; })
.MinDesiredWidth(200.f)
[
SNew(SVerticalBox)
Expand All @@ -103,7 +112,7 @@ void FClientInterestSettingsCustomization::CustomizeChildren(TSharedRef<IPropert
[
SpotsPropertyHandle->CreatePropertyNameWidget()
]
+SVerticalBox::Slot()
+ SVerticalBox::Slot()
.AutoHeight()
[
SpotsPropertyHandle->CreateDefaultPropertyButtonWidgets()
Expand All @@ -114,7 +123,7 @@ void FClientInterestSettingsCustomization::CustomizeChildren(TSharedRef<IPropert
.Padding(5, 0)
[
SNew(SBox)
.IsEnabled_Lambda([=] {return AreaType == EClientInterestAreaType::Box; })
.IsEnabled_Lambda([=] { return AreaType == EClientInterestAreaType::Box; })
.MinDesiredWidth(200.f)
[
SNew(SVerticalBox)
Expand All @@ -123,7 +132,7 @@ void FClientInterestSettingsCustomization::CustomizeChildren(TSharedRef<IPropert
[
ExtentPropertyHandle->CreatePropertyNameWidget()
]
+SVerticalBox::Slot()
+ SVerticalBox::Slot()
.AutoHeight()
[
StructBuilder.GenerateStructValueWidget(ExtentPropertyHandle.ToSharedRef())
Expand All @@ -135,7 +144,7 @@ void FClientInterestSettingsCustomization::CustomizeChildren(TSharedRef<IPropert
.Padding(5, 0)
[
SNew(SBox)
.IsEnabled_Lambda([=] {return AreaType == EClientInterestAreaType::Sphere || AreaType == EClientInterestAreaType::Cone; })
.IsEnabled_Lambda([=] { return AreaType == EClientInterestAreaType::Sphere || AreaType == EClientInterestAreaType::Cone; })
.MinDesiredWidth(70.f)
[
SNew(SVerticalBox)
Expand All @@ -144,7 +153,7 @@ void FClientInterestSettingsCustomization::CustomizeChildren(TSharedRef<IPropert
[
RadiusPropertyHandle->CreatePropertyNameWidget()
]
+SVerticalBox::Slot()
+ SVerticalBox::Slot()
.AutoHeight()
[
RadiusPropertyHandle->CreatePropertyValueWidget()
Expand All @@ -155,7 +164,7 @@ void FClientInterestSettingsCustomization::CustomizeChildren(TSharedRef<IPropert
.Padding(5, 0)
[
SNew(SBox)
.IsEnabled_Lambda([=] {return AreaType == EClientInterestAreaType::Cone; })
.IsEnabled_Lambda([=] { return AreaType == EClientInterestAreaType::Cone; })
.MinDesiredWidth(70.f)
[
SNew(SVerticalBox)
Expand All @@ -164,7 +173,7 @@ void FClientInterestSettingsCustomization::CustomizeChildren(TSharedRef<IPropert
[
AnglePropertyHandle->CreatePropertyNameWidget()
]
+SVerticalBox::Slot()
+ SVerticalBox::Slot()
.AutoHeight()
[
AnglePropertyHandle->CreatePropertyValueWidget()
Expand Down
4 changes: 4 additions & 0 deletions Source/ChanneldEditor/Widget/ChanneldIntegerSpinBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ UChanneldIntegerSpinBox::UChanneldIntegerSpinBox(const FObjectInitializer& Objec
MinDesiredWidth = 0;
ClearKeyboardFocusOnCommit = false;
SelectAllTextOnCommit = true;
#if ENGINE_MAJOR_VERSION < 5
ForegroundColor = FSlateColor(FLinearColor::Black);
#else
ForegroundColor = FSlateColor(FLinearColor::White);
#endif

if (DefaultSpinBoxStyle == nullptr)
{
Expand Down
9 changes: 7 additions & 2 deletions Source/ChanneldUE/ChanneldNetConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "unreal_common.pb.h"
#include "ChanneldUtils.h"
#include "ChanneldSettings.h"
#include <numeric>
#include "Interest/ClientInterestManager.h"

UChanneldNetConnection::UChanneldNetConnection(const FObjectInitializer& ObjectInitializer)
Expand Down Expand Up @@ -341,12 +342,16 @@ FString UChanneldNetConnection::LowLevelGetRemoteAddress(bool bAppendPort /*= fa
if (RemoteAddr)
{
if (bAppendPort)
RemoteAddr->SetPort(GetSendToChannelId());
{
// Use the native UNetConnection::ConnectionId as the port (which is limited to 1024 by default).
// If we use the GetConnId(), FInternetAddrBSD::SetPort() will throw check error when ConnId > 65535.
RemoteAddr->SetPort(GetConnectionId());
}
return RemoteAddr->ToString(bAppendPort);
}
else
{
return bAppendPort ? FString::Printf(TEXT("0.0.0.0:%d"), GetSendToChannelId()) : TEXT("0.0.0.0");
return bAppendPort ? FString::Printf(TEXT("0.0.0.0:%d"), GetConnectionId()) : TEXT("0.0.0.0");
}
}

Expand Down
2 changes: 2 additions & 0 deletions Source/ChanneldUE/ChanneldNetConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class CHANNELDUE_API UChanneldNetConnection : public UNetConnection
virtual void Tick(float DeltaSeconds) override;
virtual void ReceivedRawPacket(void* Data, int32 Count) override;

// Get the ConnectionID associated with channeld, which is different from the native UNetConnection::GetConnectionId().
FORCEINLINE Channeld::ConnectionId GetConnId() const
{
if (RemoteAddr.IsValid())
Expand All @@ -39,6 +40,7 @@ class CHANNELDUE_API UChanneldNetConnection : public UNetConnection
return 0;
}

// Get the ChannelID used for SendData() when `ChId` is not specified.
Channeld::ChannelId GetSendToChannelId();

// Send data between UE client and sever via channeld. MsgType should be in user space (>= 100).
Expand Down
1 change: 1 addition & 0 deletions Source/ChanneldUE/ChanneldNetDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ TSharedRef<FInternetAddr> UChanneldNetDriver::ConnIdToAddr(Channeld::ConnectionI
{
auto Addr = GetSocketSubsystem()->CreateInternetAddr();
Addr->SetIp(ConnId);
// Won't set the port until UChanneldNetConnection::LowLevelGetRemoteAddress(true) is called.
CachedAddr.Add(ConnId, Addr);
AddrPtr = &Addr;
}
Expand Down
8 changes: 8 additions & 0 deletions Source/ChanneldUE/ChanneldSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,18 @@ UChanneldSettings::UChanneldSettings(const FObjectInitializer& ObjectInitializer
SpatialOutlinerClass(LoadClass<AOutlinerActor>(NULL, TEXT("BlueprintGeneratedClass'/ChanneldUE/Blueprints/BP_SpatialOutliner.BP_SpatialOutliner_C'")))
{
FClientInterestSettingsPreset DefaultInterestPreset;
DefaultInterestPreset.bActivateByDefault = true;
DefaultInterestPreset.AreaType = EClientInterestAreaType::Sphere;
DefaultInterestPreset.PresetName = "ThirdPerson";
DefaultInterestPreset.Radius = 1000;
ClientInterestPresets.Add(DefaultInterestPreset);

FClientInterestSettingsPreset InspectorInterestPreset;
InspectorInterestPreset.bActivateByDefault = false;
InspectorInterestPreset.AreaType = EClientInterestAreaType::Box;
InspectorInterestPreset.PresetName = "Inspector";
InspectorInterestPreset.Extent = FVector(100000, 100000, 100000);
ClientInterestPresets.Add(InspectorInterestPreset);
}

void UChanneldSettings::PostInitProperties()
Expand Down
6 changes: 3 additions & 3 deletions Source/ChanneldUE/ChanneldUE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void FChanneldUEModule::StartupModule()
if (ISettingsModule* SettingsModule = FModuleManager::GetModulePtr<ISettingsModule>("Settings"))
{
SettingsModule->RegisterSettings("Project", "Plugins", "ChanneldSettings",
LOCTEXT("RuntimeSettingsName", "Channeld"),
LOCTEXT("RuntimeSettingsName", "Channeld"),
LOCTEXT("RuntimeSettingsDesc", ""),
GetMutableDefault<UChanneldSettings>());
}
Expand Down Expand Up @@ -60,5 +60,5 @@ void FChanneldUEModule::ShutdownModule()
}

#undef LOCTEXT_NAMESPACE
IMPLEMENT_MODULE(FChanneldUEModule, ChanneldUE)

IMPLEMENT_MODULE(FChanneldUEModule, ChanneldUE)
2 changes: 1 addition & 1 deletion Source/ChanneldUE/ChanneldUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ TSharedRef<unrealpb::UnrealObjectRef> ChanneldUtils::GetRefOfObject(UObject* Obj
ObjRef->set_owningconnid(CastChecked<UChanneldNetConnection>(Connection)->GetConnId());

auto PackageMap = Cast<UPackageMapClient>(Connection->PackageMap);

if (IsValid(PackageMap))
{
// If the NetGUID is not created yet, assign an new one and send the new NetGUID CachedObjects to the client.
Expand Down
Loading

0 comments on commit c34af74

Please sign in to comment.