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"

Dynamically allocating a UUserDefinedStruct?

I've got a blueprint function library function with the following signature:

 UFUNCTION(BlueprintCallable)
 static bool LoadSequenceTransforms(const FString& sequenceName, TArray<UeKeyedTransform*>& transforms);

The function looks like this:

 bool USequenceSaverFunctions::LoadSequenceTransforms(const FString& sequenceName, TArray<UeKeyedTransform*>& transforms)
 {
     UeKeyedTransform* transformStruct = new UeKeyedTransform();
 }

Compiles just fine, but when trying to new off transformStruct the editor crashes and I get the following error:

FObjectInitializer::Get() can only be used inside of UObject-derived class constructor.

If I can't use new to dynamically allocate memory for a UUserDefinedStruct, then how am I supposed to construct it?

Thanks!

Product Version: UE 4.16
Tags:
more ▼

asked Jun 11 '17 at 12:01 AM in C++ Programming

avatar image

Algorythmik
1 4

avatar image Teiwaz Jun 12 '17 at 10:29 PM

Not an answer, but TBH, you should reconsider trying to work with UUserDefinedStructs in C++. It's really not what they're meant for, and are extremely difficult to access and set data from C++. I went down this road a few months ago trying to build a partially-automated save system, and all I found was failure and stories of other people trying to use these and failing - including people trying to build plugins with code support from Epic. UUserDefinedStructs are horrifyingly complicated beasts.

What I ended up doing was creating a UObject which contained FName-indexed TMaps for each of the common data types. That way, end-users could define custom data they needed to save in editable arrays or via accessors. This data was then either trivially easy to serialize, or in the case of UObjects, I could easily do my own cleanup to convert object pointers into a format which would survive save/load.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

0 answers: sort voted first
Be the first one to answer this question
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