x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

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.

Product Version: Not Selected
Tags:
more ▼

asked Dec 03 '14 at 11:12 AM in C++ Programming

avatar image

Diddykonga
100 14 18 25

avatar image Mercurial Forge Jan 23 '15 at 10:02 AM

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 ++;
(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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

Doug Wilson

more ▼

answered Jan 05 '16 at 05:05 PM

avatar image Asusralis Apr 21 '16 at 03:57 AM

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?

avatar image Doug E ♦♦ STAFF Apr 22 '16 at 03:00 PM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question