/ProtobufBlueprintSp

一个能让Protobuf在蓝图中使用的UE5插件

Primary LanguageC++Apache License 2.0Apache-2.0

ProtobufBlueprintSp

一个能让Protobuf在蓝图中使用的插件

  • UE 5.3
  • Protobuf 3.19

支持类型

单一类型

proto 蓝图 U++
int32/sint32/sfixed32 int32 int32
int64/sint64/sfixed64 int64 int64
uint32/fixed32 - uint32
uint64/fixed64 - uint64
double double double
float - float
bool bool bool
enum enum uint8
string string/TArray<uint8> FString/TArray<uint8>
bytes TArray<uint8> TArray<uint8>
message UProtobufMessage蓝图子类 UProtobufMessage*
map - -

数组类型(repeated)

proto 蓝图 U++
int32/sint32/sfixed32 TArray<int32> TArray<int32>
int64/sint64/sfixed64 TArray<int64> TArray<int64>
uint32/fixed32 - TArray<uint32>
uint64/fixed64 - TArray<uint64>
double TArray<double> TArray<double>
float TArray<float> TArray<float>
bool TArray<bool> TArray<bool>
enum TArray<enum> TArray<uint8>
string TArray<FString> TArray<FString>
bytes - -
message TArray<UProtobufMessage蓝图子类> TArray<UProtobufMessage*>

使用方法

  1. 编写.proto文件

  2. 使用protoc.exe生成.pb.h.pb.cc文件

  3. 在以下文件里注册新生成的消息

    image-20240117172032592

  4. 蓝图派生ProtobufMessage

  5. 类默认值里编辑标识符(新添加消息的标识符)

    image-20240117172158977

  6. 蓝图添加proto文件里的变量([详情请看](#2. 蓝图变量分类))

  7. 之后就可以调用函数进行序列化和反序列化等操作了( •̀ ω •́ )✧

    • 相关函数在Protobuf|Util分类下

工具

位于如下路径:

PROJECT_DIR/Plugins/ProtobufBlueprintSp/Content/Utils

image-20240117231047564

  • AutoCompileProto
    • 是后面2个的整合版,适用于新定义了.proto文件,想要编译并注册的场景
  • CompileProtoEUB
    • 只提供编译.proto文件的功能
  • ProtoRegisterMessageEUB
    • 只提供消息注册的功能

注意事项

1. proto变量命名

proto文件中的变量名称需要为snake_case风格

例如:.proto文件如下:

syntax = "proto3";

message TestMessageReq {
  bool bool_val = 1;
  int32 int32_val = 2;
  int64 int64_val = 3;
  double double_val = 4;
  string string_val = 5;
  bytes bytes_val = 6;
  repeated bool bool_vals = 7;
  repeated int32 int32_vals = 8;
  repeated int64 int64_vals = 9;
  repeated double double_vals = 10;
  repeated string string_vals = 11;
  repeated bytes bytes_vals = 12;
}

2. 蓝图变量分类

继承自ProtobufMessage的蓝图类在对proto消息变量创建时,需要将变量放至Protobuf|Property分类下

Protobuf|Property

image-20240117143611069

image-20240117143624656