TUniquePtr in UStruct

I am trying to get an unique pointer to work in Ustruct, but couldnt figure it out for the life of me. Any help for c++ noob?

USTRUCT()
struct FQuadArrtype {
	GENERATED_BODY()
		FQuadArrtype() {}
	FBox2D BoxA;
	
	FQuadArrtype(FBox2D AA):BoxA(AA) {
		QuadTreeYY = MakeUnique<QuadTreeY>(BoxA, 50);
	}
	typedef TQuadTree<int32> QuadTreeY;
	TUniquePtr<QuadTreeY> QuadTreeYY;
};

2>c:\program files\epic games\ue_4.15\engine\source\runtime\coreuobject\public\UObject/Class.h(662): error C2280: ‘FQuadArrtype &FQuadArrtype::operator =(const FQuadArrtype &)’: attempting to reference a deleted function
2> F:\Unreal Projects\SpriteGroupComponent\Source\SpriteGroupComponent\SpriteGroupManager.h(22): note: compiler has generated ‘FQuadArrtype::operator =’ here

Hi,

The reflection system expects UStructs to be copy assignable. If this is not the case, you should add a type traits specialisation immediately after your class to tell the reflection system that it is non-copyable:

template <>
struct TStructOpsTypeTraits<FQuadArrtype> : public TStructOpsTypeTraitsBase
{
    enum { WithCopy = false };
};

Note that in 4.16, TStructOpsTypeTraitsBase will be changed to TStructOpsTypeTraitsBase2.

Hope this helps,

Steve

Thanks Steve, you are awesome!

// .h
typedef TQuadTree<int32> QuadTreeY;

USTRUCT()
struct  FQuadArrtype {
	GENERATED_BODY()
		FQuadArrtype() {}
	TUniquePtr<QuadTreeY> QuadTreeYY;
	FQuadArrtype(FBox2D AA) {
		QuadTreeYY = MakeUnique<QuadTreeY>(AA, 50);
	}
};

template<>
struct  TStructOpsTypeTraits<FQuadArrtype> : public TStructOpsTypeTraitsBase { // in 4.16 changed to TStructOpsTypeTraitsBase2
	enum { WithCopy = false };
};