Skip to content

slua.Array创建直接返回nil #617

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

Open
scriptkitz opened this issue Oct 31, 2024 · 9 comments
Open

slua.Array创建直接返回nil #617

scriptkitz opened this issue Oct 31, 2024 · 9 comments

Comments

@scriptkitz
Copy link
Contributor

scriptkitz commented Oct 31, 2024

local arr = slua.Array(EPropertyClass.Int) -- 这个返回正常
local arr2 = slua.Array(EPropertyClass.Byte) -- 这个返回nil并没有任何报错信息。

@scriptkitz
Copy link
Contributor Author

以前版本c++的蓝图函数参数为: TArray<TEnumAsByte > 类型的,可以直接传入slua.Array(EPropertyClass.Int)就可以, 但现在新版本,不知道怎么在lua创建这种类型的参数了,slua.Array(EPropertyClass.Byte) 不行slua.Array(EPropertyClass.Enum) 也不行。。。。。。~~~!!!

@zjhongxian
Copy link
Collaborator

local EPropertyClass = import("EPropertyClass")
local arr = slua.Array(EPropertyClass.Int)
试试这样呢?新版本UE api有些差异

@scriptkitz
Copy link
Contributor Author

scriptkitz commented Nov 1, 2024

local EPropertyClass = import("EPropertyClass") local arr = slua.Array(EPropertyClass.Int) 试试这样呢?新版本UE api有些差异

这样不行,会提示报错,TArray 需要Byte 属性类型。
KismetSystemLibrary.LineTraceSingleForObjects(...) 的一个参数类型是TArray<TEnumAsByte<\EObjectTypeQuery>\ >,
我暂时是注释了:
static inline bool isBinStringProperty(FProperty* inner)
{
if (FByteProperty::StaticClass()->IsChildOf(inner->GetClass()))
{
//auto byteProperty = CastField(inner);
//return byteProperty->Enum == nullptr; 暂时注释掉, 这样可以用 slua.Array(EPropertyClass.Byte) 了
}
return false;
}

@zjhongxian
Copy link
Collaborator

这样是否可行?
local EPropertyClass = import("EPropertyClass")
local arr = slua.Array(EPropertyClass.ENum)

@scriptkitz
Copy link
Contributor Author

这样是否可行? local EPropertyClass = import("EPropertyClass") local arr = slua.Array(EPropertyClass.ENum)

不行啊,代码里没有对ENum的参数类型情况的处理。

@scriptkitz
Copy link
Contributor Author

scriptkitz commented Nov 4, 2024

这样是否可行? local EPropertyClass = import("EPropertyClass") local arr = slua.Array(EPropertyClass.ENum)

我使用最新代码的,但还是崩溃:
Script Stack (0 frames) :

Assertion failed: UnderlyingProp [File:H:\ue54\Engine\Source\Runtime\CoreUObject\Private\UObject\EnumProperty.cpp] [Line: 390]

A breakpoint instruction (__debugbreak() statement or a similar call) was executed in UnrealEditor-Win64-Debug.exe.

图片

感觉要再对FEnumProperty的实例要具体的Enum类型的初始化。

而且,我感觉就算这个问题修正了,还是不行。。。

因为类型是:TArray<TEnumAsByte<\EObjectTypeQuery>\ >,需要的元素类型是Byte。不是Enum。

还是处理一下:isBinStringProperty这个函数的判断办法。。比如当local arr = slua.Array(EPropertyClass.Byte)创建这种类型时候,添加一个标记,isBinStringProperty里判断这个标记,之类的什么办法。。。

@zjhongxian
Copy link
Collaborator

明白了,你需要的是
local EPropertyClass = import("EPropertyClass")
local arr = slua.Array(EPropertyClass.Byte)
的支持是吧?

@zjhongxian
Copy link
Collaborator

这样是否可行? local EPropertyClass = import("EPropertyClass") local arr = slua.Array(EPropertyClass.ENum)

我使用最新代码的,但还是崩溃: Script Stack (0 frames) :

Assertion failed: UnderlyingProp [File:H:\ue54\Engine\Source\Runtime\CoreUObject\Private\UObject\EnumProperty.cpp] [Line: 390]

A breakpoint instruction (__debugbreak() statement or a similar call) was executed in UnrealEditor-Win64-Debug.exe.

图片

感觉要再对FEnumProperty的实例要具体的Enum类型的初始化。

而且,我感觉就算这个问题修正了,还是不行。。。

因为类型是:TArray<TEnumAsByte<\EObjectTypeQuery>\ >,需要的元素类型是Byte。不是Enum。

还是处理一下:isBinStringProperty这个函数的判断办法。。比如当local arr = slua.Array(EPropertyClass.Byte)创建这种类型时候,添加一个标记,isBinStringProperty里判断这个标记,之类的什么办法。。。

你是什么版本的UE?我这边 local arr = slua.Array(EPropertyClass.ENum) 是可以成功跑的(UE 5.2)

@scriptkitz
Copy link
Contributor Author

scriptkitz commented Nov 5, 2024

我用的最新版UE5.4.4

需要再lua里调用UE的射线碰撞函数:
local KismetSystemLibrary = import("KismetSystemLibrary")
local objs = slua.Array(EPropertyClass.Byte)
objs:Add(ConvertToObjectType(ECollisionChannel.ECC_Vehicle))
KismetSystemLibrary.LineTraceSingleForObjects(..., objs, ....);

objs 是一个TArray<TEnumAsByte<\EObjectTypeQuery>\ > 类型。
所以在lua里貌似是需要slua.Array(EPropertyClass.Byte)这种类型。

我现在是直接把isBinStringProperty内的那个return注释了,现在代码运行正常。
但不知道isBinStringProperty里的那个判断是干啥的会有什么其他什么影响。。。

zjhongxian added a commit to zjhongxian/sluaunreal that referenced this issue Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants