Should my Data Objects be UStructs or UObjects?

PaperSkeletonData.h


(Key UStruct Definitions Above)


USTRUCT()
struct FPaperSkeletonTimelineData
{
	GENERATED_USTRUCT_BODY()
        
        // UPROPERTY()
        // struct FPaperSkeletonAnimationData* Owner; <-- Throws error, saying "*" cant be added to a non-exposable type.

	// Unique ID
	UPROPERTY(EditAnywhere)
	FName Name;

	UPROPERTY(EditAnywhere)
	EPaperSkeletonDataType DataType;

	// Keys
	UPROPERTY(EditAnywhere)
	TArray<FPaperSkeletonBaseKeyData> Keys;

	FPaperSkeletonTimelineData(){}

	FPaperSkeletonTimelineData(FName timelineName, TArray<FPaperSkeletonBaseKeyData>& keys)
		: Name(timelineName), Keys(keys)
	{
	}

	FPaperSkeletonBaseKeyData FindKey(float atTime);

};

USTRUCT()
struct FPaperSkeletonAnimationData
{
	GENERATED_USTRUCT_BODY()

	// Skeleton Data (Owner)
	class UPaperSkeletonData* SkeletonOwner;

	// Name of the Animation
	UPROPERTY(EditAnywhere)
	FName Name;

	// Duration of the Animation
	UPROPERTY(EditAnywhere)
	float Duration;

	// Should the animation loop?
	UPROPERTY(EditAnywhere)
	bool bShouldLoop;

	// Timelines/Objects relative to the Animation 
	UPROPERTY(EditAnywhere)
	TArray<FPaperSkeletonTimelineData> Timelines;

	FPaperSkeletonAnimationData(){}

	FPaperSkeletonAnimationData(UPaperSkeletonData* skeletonOwner, FName animationName, float duration, bool shouldLoop, TArray<FPaperSkeletonTimelineData>& timelines)
		: SkeletonOwner(skeletonOwner), Name(), Duration(duration), bShouldLoop(shouldLoop), Timelines(timelines)
	{
	}

	bool IsActive(FName objectName);

	FPaperSkeletonTimelineData FindTimeline(FName objectName);

};

UCLASS(BlueprintType, meta=(DisplayThumbnail="true"))
class PAPERTESTREALM_API UPaperSkeletonData : public UDataAsset
{
	GENERATED_BODY()

public:
	// Skeleton Name
	UPROPERTY(EditAnywhere)
	FName Name;

        // Definition of Objects that need to be created for the Skeleton
	UPROPERTY(EditAnywhere)
	TArray<FPaperSkeletonObjectDefinition> ObjectDefinitions;

	// Skeleton Animations
	UPROPERTY(EditAnywhere)
	TArray<FPaperSkeletonAnimationData> Animations;

	FPaperSkeletonAnimationData FindAnimation(FName animationName);
};

Should i keep them as UStructs or UObjects instead?

Keeping a pointer to a Higher-Level Data Object that owns the above Data Object is another necessity i cant seem to pull off right now.
(See above code struct FPaperSkeletonAnimationData* AnimationOwner;)

I want to be able to pass around my Data Objects as pointers or references to make sure all other classes that access them, are accessing the most recent/updated version of them in the UPaperSkeletonData asset class.

I would love to know the answer to this as well. Getting data from Data Tables is great but being unable to pass it around as a pointer via struct at runtime is a big problem when you have things like equipment that needs to point to an inventory.

My assumption would be to store the Structs in a UObject Wrapper. Then point to the wrapper and edit as needed?

Simple Example:

//Inventory
TArray<UArmorWrapper> Armors;

//Character's Equipment
UArmorWrapper* EquippedArmor;

//Function
EquippedArmor->FArmorData.Degradation ++;

Hey Diddykonga and Oliver-

It is possible to have a pointer to a struct however it cannot be declared as a UPROPERTY which means it will only be available inside the code and cannot be used in the editor. Using Diddykong’s structs as an example, removing the UPROPERTY() from line 9 and uncommenting line 10 should allow the code to compile successfully.

Cheers

If I needed to use structure pointers, and I also need replication and to expose on spawn, how would I do that?

I’m make an inventory system with inherited structures. Because of this, I can’t pass structures by value to the array that would hold the items. Do you know a good workaround for this?

Hey Asusralis-

Something you can try would be to create a class based on Data Asset. If you create your struct inside the data asset class you can define the defaults of your inventory in the struct, then you can create a pointer variable marked as UPROPERTY with replication to access / use the data asset struct elements.