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"

Getting a variable from FAssetData in UObjectLibrary

I want to get a variable from my objects in UObjectLibrary. The variable is defined in c++ in the AObject class, only the cast to this class returns null. The object in the library that i use for testing is a blueprint with as parentclass AObject. I hope someone has a solution.

 UClass* cls = TSubclassOf<class AObject>();
     auto ObjectLibrary = UObjectLibrary::CreateLibrary(cls, false, true);
     TArray<FAssetData> AssetDatas;
     UE_LOG(LogTemp, Warning, TEXT("Found objects: %d"), AssetDatas.Num());
     AObject* object = Cast<AObject>(AssetDatas[0].GetAsset()); //Always returns null
     UE_LOG(LogTemp, Warning, TEXT("Variable: %i", object->variable));
Product Version: UE 4.16
more ▼

asked Jul 12 '17 at 03:23 PM in C++ Programming

avatar image

3 1 3

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

1 answer: sort voted first

You have to load the asset into memory before you can access it.

more ▼

answered Jul 12 '17 at 04:35 PM

avatar image

531 20 8 27

avatar image MatzeOGH Jul 12 '17 at 04:51 PM


returnes the UObject if it can

avatar image sjoerdcr Jul 12 '17 at 09:52 PM

Thank you for the reply, but I still have a problem with casting. The objectInMemory is not null, but the object still is.

 UObject* objectInMemory = AssetDatas[0].ToStringReference().TryLoad();
 AObject* object = Cast<AObject>(objectInMemory);
avatar image MatzeOGH Jul 12 '17 at 11:02 PM

Are you certain that the first asset data object is of class AObject?

avatar image sjoerdcr Jul 13 '17 at 08:39 AM

Yes, I found out that i can access the variable if i spawn the object with:


But i think it is not very efficient

avatar image MatzeOGH Jul 13 '17 at 09:44 AM

If it is a class that you want to spawn you can do something like: getClass()->GetDefaultObject()

That way you get the CDO of the class. Doesn't work with pure assets though.

avatar image sjoerdcr Jul 13 '17 at 09:58 AM

This works, thank you!

(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