Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UE DataTable枚举类型 #31

Open
007havegone opened this issue May 16, 2023 · 20 comments
Open

UE DataTable枚举类型 #31

007havegone opened this issue May 16, 2023 · 20 comments

Comments

@007havegone
Copy link

我看example里面都是将Enumeration单独定义在一个 proto内,随后其他proto编译时 -I引入使用。看起来似乎不支持定义在一个proto内同时导出在一个UE .h文件内。
我使用自带的java编译命令,使用一个proto同时定义了枚举和message,使用-t 导出UE的json,使用 -f -m导出相应的cpp,.h但是其中的头文件没有成功包含枚举类型信息,如果使用了-c参数导出的cpp和.h名字和 -m内指定的信息冲突,同时导出的内容将枚举信息识别成一个message。

@owent owent added the question label May 17, 2023
@owent
Copy link
Owner

owent commented May 17, 2023

没看懂问题呢?enum定义在一个proto还是多个proto里是无所谓的。
-c的UE输出的枚举信息在json文件里,最终是import到UE的uassert里的,类型名和指定输出的文件名有关。
因为整个pb结构是带package(对应C++的namespace)的,而UE的enum要支持蓝图不能带namespace,所以所有的名字字段用数据Name的字段表示了,没有直接输出代码。

@007havegone
Copy link
Author

发现枚举最终都是产生unit32,我实际用到枚举值可能就十几个,用uint8就可以覆盖了,可以支持proto配置生成 uint8么?

@owent
Copy link
Owner

owent commented May 18, 2023

发现枚举最终都是产生unit32,我实际用到枚举值可能就十几个,用uint8就可以覆盖了,可以支持proto配置生成 uint8么?

目前不支持,其实应该产生int32的,我后面加个选项可以指定某些enum生成的base类型吧。

@owent owent self-assigned this May 18, 2023
@007havegone
Copy link
Author

做RPG游戏时,Datable里面经常会用到UE里面的FGameplayTag作为type类型,而不是简单的枚举变量。这个能否支持?

@owent
Copy link
Owner

owent commented May 18, 2023

可以,我记一下后续有空的时候写支持吧。

@007havegone
Copy link
Author

007havegone commented May 18, 2023

message ItemProperty
{
    option (org.xresloader.ue.helper)       = "helper";
    option (org.xresloader.msg_description) = "ItemProperty helper";

    uint32 ID = 1 [ (org.xresloader.ue.key_tag) = 1];
    string ItemType = 2 [ (org.xresloader.ue.ue_type_name) = "FGameplayTag", (org.xresloader.ue.ue_type_is_class) = true];
}
USTRUCT(BlueprintType)
struct EXCELCLIENT_API FItemProperty : public FTableRowBase
{
    GENERATED_USTRUCT_BODY()

    // Start of fields
    /** Field Type: STRING, Name: Name, Index: 0. This field is generated for UE Editor compatible. **/
    UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "XResConfig")
    FName Name;

    /** Field Type: INT, Name: ID, Index: 1 **/
    UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "XResConfig")
    int32 ID;

    /** Field Type: STRING, Name: ItemType, Index: 2 **/
    UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "XResConfig")
    TSoftClassPtr< FGameplayTag > ItemType;

};

这样能够用上FGameplayTag,但是他会构成指针,由于指针,生成的datatable没发正常识别成gametag。

@owent
Copy link
Owner

owent commented May 18, 2023

message ItemProperty
{
    option (org.xresloader.ue.helper)       = "helper";
    option (org.xresloader.msg_description) = "ItemProperty helper";

    uint32 ID = 1 [ (org.xresloader.ue.key_tag) = 1];
    string ItemType = 2 [ (org.xresloader.ue.ue_type_name) = "FGameplayTag", (org.xresloader.ue.ue_type_is_class) = true];
    string NameID = 3;
    string DescID = 4;
    uint32 IconID = 5;
    uint32 MeshID = 6;
    uint32 SkillID = 7;
}
USTRUCT(BlueprintType)
struct EXCELCLIENT_API FItemProperty : public FTableRowBase
{
    GENERATED_USTRUCT_BODY()

    // Start of fields
    /** Field Type: STRING, Name: Name, Index: 0. This field is generated for UE Editor compatible. **/
    UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "XResConfig")
    FName Name;

    /** Field Type: INT, Name: ID, Index: 1 **/
    UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "XResConfig")
    int32 ID;

    /** Field Type: STRING, Name: ItemType, Index: 2 **/
    UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "XResConfig")
    TSoftClassPtr< FGameplayTag > ItemType;

    /** Field Type: STRING, Name: NameID, Index: 3 **/
    UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "XResConfig")
    FString NameID;

    /** Field Type: STRING, Name: DescID, Index: 4 **/
    UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "XResConfig")
    FString DescID;

    /** Field Type: INT, Name: IconID, Index: 5 **/
    UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "XResConfig")
    int32 IconID;

    /** Field Type: INT, Name: MeshID, Index: 6 **/
    UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "XResConfig")
    int32 MeshID;

    /** Field Type: INT, Name: SkillID, Index: 7 **/
    UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "XResConfig")
    int32 SkillID;

};

这样能够用上FGameplayTag,但是他会构成指针,指针是没必要的。

这是指向类型的,不是设置最底层的类型。这个功能需要改代码的,现在不支持。

@007havegone
Copy link
Author

好的

message ItemProperty
{
    option (org.xresloader.ue.helper)       = "helper";
    option (org.xresloader.msg_description) = "ItemProperty helper";

    uint32 ID = 1 [ (org.xresloader.ue.key_tag) = 1];
    string ItemType = 2 [ (org.xresloader.ue.ue_type_name) = "FGameplayTag", (org.xresloader.ue.ue_type_is_class) = true];
    string NameID = 3;
    string DescID = 4;
    uint32 IconID = 5;
    uint32 MeshID = 6;
    uint32 SkillID = 7;
}
USTRUCT(BlueprintType)
struct EXCELCLIENT_API FItemProperty : public FTableRowBase
{
    GENERATED_USTRUCT_BODY()

    // Start of fields
    /** Field Type: STRING, Name: Name, Index: 0. This field is generated for UE Editor compatible. **/
    UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "XResConfig")
    FName Name;

    /** Field Type: INT, Name: ID, Index: 1 **/
    UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "XResConfig")
    int32 ID;

    /** Field Type: STRING, Name: ItemType, Index: 2 **/
    UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "XResConfig")
    TSoftClassPtr< FGameplayTag > ItemType;

    /** Field Type: STRING, Name: NameID, Index: 3 **/
    UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "XResConfig")
    FString NameID;

    /** Field Type: STRING, Name: DescID, Index: 4 **/
    UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "XResConfig")
    FString DescID;

    /** Field Type: INT, Name: IconID, Index: 5 **/
    UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "XResConfig")
    int32 IconID;

    /** Field Type: INT, Name: MeshID, Index: 6 **/
    UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "XResConfig")
    int32 MeshID;

    /** Field Type: INT, Name: SkillID, Index: 7 **/
    UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "XResConfig")
    int32 SkillID;

};

这样能够用上FGameplayTag,但是他会构成指针,指针是没必要的。

这是指向类型的,不是设置最底层的类型。这个功能需要改代码的,现在不支持。

了解了,谢谢。

@007havegone
Copy link
Author

了解了。

@007havegone
Copy link
Author

007havegone commented May 18, 2023

能否支持Enum不替换为int32,同时.h文件生成我们在proto中定义 enum定义。替换为int是为了能够在蓝图中处理吗?

@007havegone
Copy link
Author

007havegone commented May 19, 2023

https://www.youtube.com/watch?v=1CE6JIkMgXc&t=53s
可以参考下,一般项目中需要创建Enumeration和DataTable的Assset,另外还有CurveTable。希望能够通过Excel最后生成相应的代码和资产创建所需的数据。像枚举变量和GamePlayTag在技能和AI中是重度依赖的,一般项目在DataTable中都会使用到。

@owent
Copy link
Owner

owent commented May 19, 2023

https://www.youtube.com/watch?v=1CE6JIkMgXc&t=53s 可以参考下,一般项目中需要创建Enumeration和DataTable的Assset,另外还有CurveTable。希望能够通过Excel最后生成相应的代码和资产创建所需的数据。像枚举变量和GamePlayTag在技能和AI中是重度依赖的,一般项目在DataTable中都会使用到。

OK,后面也加选项可以自定义设置这类StaticMesh的修饰吧。然后特殊处理一下 TagName输出成JSON的形式,感觉就可以了?

@007havegone
Copy link
Author

https://www.youtube.com/watch?v=1CE6JIkMgXc&t=53s 可以参考下,一般项目中需要创建Enumeration和DataTable的Assset,另外还有CurveTable。希望能够通过Excel最后生成相应的代码和资产创建所需的数据。像枚举变量和GamePlayTag在技能和AI中是重度依赖的,一般项目在DataTable中都会使用到。

OK,后面也加选项可以自定义设置这类StaticMesh的修饰吧。然后特殊处理一下 TagName输出成JSON的形式,感觉就可以了?

嗯,这样子可以更加全面的支持UE常见的表格相关资产,而不仅仅是DataTable。

@owent
Copy link
Owner

owent commented May 19, 2023

https://www.youtube.com/watch?v=1CE6JIkMgXc&t=53s 可以参考下,一般项目中需要创建Enumeration和DataTable的Assset,另外还有CurveTable。希望能够通过Excel最后生成相应的代码和资产创建所需的数据。像枚举变量和GamePlayTag在技能和AI中是重度依赖的,一般项目在DataTable中都会使用到。

另外现在通过设置 ue_type_name ,应该只是多一层指针而已?因为这个转表工具毕竟没法包含UE的全部类型规则,如果允许自定义的话,就没法保证数据合法性了。

@007havegone
Copy link
Author

007havegone commented May 19, 2023

https://www.youtube.com/watch?v=1CE6JIkMgXc&t=53s 可以参考下,一般项目中需要创建Enumeration和DataTable的Assset,另外还有CurveTable。希望能够通过Excel最后生成相应的代码和资产创建所需的数据。像枚举变量和GamePlayTag在技能和AI中是重度依赖的,一般项目在DataTable中都会使用到。

另外现在通过设置 ue_type_name ,应该只是多一层指针而已?因为这个转表工具毕竟没法包含UE的全部类型规则,如果允许自定义的话,就没法保证数据合法性了。

嗯,我目前是使用导出cpp,.h编译后,使用UE的DataTable import命令将json导出,没详细测试如果数据是不符合改列所定义的类型的各种情况。但是会报错,如果你当前列指定了StaticMesh,但你实际填的路径不是一个Static Mesh,会显示资源找不到,你可以测试下。

@007havegone
Copy link
Author

007havegone commented May 19, 2023

像StringTable似乎只能通过csv导入,而不是json,StringTable不需要定义RowBase,也不用cpp代码,你可以给xresloader增加导出csv功能,这块用python也很容易实现。所以我是把excel的xlsx转换为csv后通过代码导入的。像Enumeration表,我没详细研究他导入所需要的数据格式。

@owent
Copy link
Owner

owent commented May 19, 2023

像StringTable似乎只能通过csv导入,而不是json,StringTable不需要定义RowBase,也不用cpp代码,你可以给xresloader增加导出csv功能,这块用python也很容易实现。所以我是把excel的xlsx转换为csv后通过代码导入的。像Enumeration表,我没详细研究他导入所需要的数据格式。

本来就支持CSV格式输出的。

我加了 org.xresloader.ue.ue_origin_type_nameorg.xresloader.ue.ue_origin_type_default_value 用来支持上面这种自定义类型的情况了,把 org.xresloader.ue.ue_origin_type_name设置成 FGameplayTagUStaticMesh 应该就能实现上面视频里的效果了。
可能也需要配合 org.xresloader.ue.ue_origin_type_default_value 来设置初始化代码。
但是还没测试,所以也没发布。

@007havegone
Copy link
Author

007havegone commented May 19, 2023

可以的,如果想csv支持StringTable导入可能得Name去除,或者不在第一,第二列,因为StringTable前两列是固定使用Key和SourceString。其他数据列会当作MetaData处理。否则不能正常导入。StringTable只要前csv两列的名字满足要求,同时key值唯一就可以了。
这块你可以参考UE官方文档:https://docs.unrealengine.com/5.1/zh-CN/using-string-tables-for-text-in-unreal-engine/

@007havegone
Copy link
Author

007havegone commented Feb 19, 2024

发现枚举最终都是产生unit32,我实际用到枚举值可能就十几个,用uint8就可以覆盖了,可以支持proto配置生成 uint8么?

目前不支持,其实应该产生int32的,我后面加个选项可以指定某些enum生成的base类型吧。

作者你好,目前新版本支持指定enum为C++代码定义的枚举类吗,而不是默认uint32

@owent
Copy link
Owner

owent commented Feb 19, 2024

发现枚举最终都是产生unit32,我实际用到枚举值可能就十几个,用uint8就可以覆盖了,可以支持proto配置生成 uint8么?

目前不支持,其实应该产生int32的,我后面加个选项可以指定某些enum生成的base类型吧。

作者你好,目前新版本支持指定enum为C++代码定义的枚举类吗,而不是默认uint32

我们现在逐渐迁移成使用 https://github.com/owent/xres-code-generator 接入UE支持了。这个工具支持直接输出枚举类型,且enum最大值小于256的时候的输出的类型支持蓝图。
并且可以从二进制读配置和支持多版本和多重索引。

老的代码输出应该是可以通过 org.xresloader.ue.ue_origin_type_name 来设置输出的类型。自己设置类型的话要自己保证类型正确。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants