C++ USTRUCT and custom constructor


#1

Hi,
I have a trouble with a following scenario, possibly with understanding the proper use of SK in this case:

MyStruct - USTRUCT defined in C++, it has some non-primitive type members
MyActor - C++ actor with USkookumScriptClassDataComponent added in OnConstruction

Now for SK side:

This works:
MyActor! - calls MyStruct! and initializes all members of MyStruct

This crashes:
MyActor! - calls a custom defined constructor MyStruct!init that initializes members of MyStruct, some of them non primitive, so with ! constructors

A workaround for above:
MyActor! - calls a ‘Class member’ method in MyStruct called init()C instead of instance constructor !init

If I would bet on the source of the crash it would be the nested ! calls inside ustructs !
The workaround works but I would prefer using the SK initialization.

The crash occurs in most cases iniside USkookumScriptDataComponent::create_sk_instance however I’ve seen it pop up elsewhere.

Let me know if there’s something that I’m doing wrong.

Thanks


#2

Hi Pew - currently you can only invoke a struct’s default constructor from SkookumScript. Your workaround is correct for what you intend to do.