TUnion and TArray

Hello guys, i’m working on Windows, with branch 4.6.
Here’s some code:

USTRUCT()
struct FDataUnion
{
	GENERATED_USTRUCT_BODY()
	TUnion<FVector, UObject*> Union;
};

USTRUCT()
struct FCommandInfo
{
	GENERATED_USTRUCT_BODY()
	TArray<uint32> UnitIds;
	FDataUnion Data;  //simple union
};

In a UObject derived class, this compiles without problem, but if i try to make an array:

USTRUCT()
struct FDataUnion
{
	GENERATED_USTRUCT_BODY()
	TUnion<FVector, UObject*> Union;
};

USTRUCT()
struct FCommandInfo
{
	GENERATED_USTRUCT_BODY()
	TArray<uint32> UnitIds;
	TArray<FDataUnion> Data;  //array of unions
};

i get this strange compiling error:

 [17/17] Link UE4Editor-Impero.dll
1>    Creating of library  ****\Intermediate\Build\Win64\ImperoEditor\Development\UE4Editor-Impero.lib and the object ****\Intermediate\Build\Win64\ImperoEditor\Development\UE4Editor-Impero.exp ...
1>Impero.generated.cpp.obj : error LNK2001: unresolved external symbol "struct FLogCategoryLogUnion LogUnion" (?LogUnion@@3UFLogCategoryLogUnion@@A)
1>****\Binaries\Win64\UE4Editor-Impero.dll : fatal error LNK1120: 1 external not solved

(note, i slightly modified and translated the output)

It’s the first time i find thiss error, and there’s no info about it.
Even removing the USTRUCT macros from FDataUnion doesn’t help.

A TArray (of the first version, with simple union) works instead.

Not any particular reason, i’m just testing some stuffs. I’ll try to add UPROPERTYs

I’ll send it on a server replicated function, so i don’t want the transient flag :slight_smile:

Anyway, i can’t set the UPROPERTY on FDataUnion::Union, it states

Unrecognized type ‘TUnion’

The error suggest that your are using a log incorrectly but nothing related to your structs. Is there any reason why you are not using UPROPERTYs?

If you do not want to serialize the content of the properties, if they are only populated and used in runtime, you can use the transient property flag.

:smiley: so it’s working?

Do you use ‘LogUnion’ somewhere? It seams to be a UE_LOG category.

i forgot: it requires ofc his include:

#include "Union.h"

No moss, i already had the include, i forgot to mention it if someone wants to try the code :slight_smile:

The situation didn’t change :frowning:

Nope. Just created this 2 structs. I just have it in my class to test if it compiles with a

TArray<FCommandInfo> t;

But i added it later, the problem is present just declaring those structs as they are written in here

I’ll make a test this afternoon and post my results ^^

ok, now this is strange:

using this struct

USTRUCT()
struct FDataUnion
{
	GENERATED_USTRUCT_BODY()
	TUnion<FVector, UObject*> Union;
};

in another struct with an array, like this:

USTRUCT()
struct FCommandInfo
{
	GENERATED_USTRUCT_BODY()
	UPROPERTY()
	TArray<FTempStruct> Data;
};

will generate the compile error just with the declaration, but if we use it directly in a class like this:

UCLASS()
class UCommand : public UObject
{
	GENERATED_BODY()
public:
	TArray<FDataUnion> t;
};

will work.

I’m going to look closely at the TUnion declaration.

Meanwhile, thank you for your interest Moss :slight_smile:

The log category is declared in Union.h:

DECLARE_LOG_CATEGORY_EXTERN(LogUnion, Log, All);

Aaaaaand that’s it.

in Union.cpp:

// Seemingly not used, because it doesn't compile!
//#include "Union.h"

//DEFINE_LOG_CATEGORY(LogUnion);

we have a log category non fully defined.

So, i found out the problem:

Union.cpp is fully commented out, so we’re missing the Log category implementation.

In fact, adding the line

DEFINE_LOG_CATEGORY(LogUnion);

in my class cpp file allowed it to compile without errors.

I suggest to check out and fix the Union.cpp file.

It doesn’t work even uncommenting Union.cpp

Then maybe remove the log category?

Is there a way i can open a ticket, or it must be a staff member to open it?