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"

UE Reflection - how to get Type of TArray elements?

Hello. How to get Type of TArray elements with UE reflection? For example, I have some array:

     UMySaveGame* save = Cast<UMySaveGame>(UGameplayStatics::CreateSaveGameObject(UMySaveGame::StaticClass()));

     TArray<FString> sa;
 sa.Add(TEXT("TEXT0"));
 sa.Add(TEXT("TEXT1"));
 sa.Add(TEXT("TEXT2"));
 save->MyStrArrProp = sa;

and I want to access it with the reflection:

 UClass* SourceObjectClass = save->GetClass();
     TMap<FString, UProperty*> Props;
     for (TFieldIterator<UProperty> PropIt(SourceObjectClass, EFieldIteratorFlags::SuperClassFlags::IncludeSuper);
     PropIt; ++PropIt)
     {
         Props.Add(*PropIt->GetNameCPP(), *PropIt);
     }
 for (auto p : Props) {

 GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green,
                 TEXT("PROP NAME: ") + p.Key +
                 TEXT(" - TYPE: ") + p.Value->GetCPPType()
                 //TEXT(" - VALUE: ") + (*ValuePtr)
                 );
 }

It shows only TArray for p.Value->GetCPPType() . But how to check, what type of values of that TArray? Ie, it can be, for example TArray.

Thank you!

Product Version: UE 4.11
Tags:
more ▼

asked Apr 15 '16 at 12:36 PM in C++ Programming

avatar image

Arthur Khusnutdinov
605 89 95 250

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

1 answer: sort voted first

Solution is very simple, as it turned out:

 for (auto p : Props) {
    if (p.Value->GetCPPType().Equals(TEXT("TArray"))) {
        UArrayProperty* ArrayProp = Cast<UArrayProperty>(p.Value);
 
        GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green,
               TEXT("PROP NAME: ") + p.Key +
                 TEXT(" - TYPE: ") + ArrayProp->Inner->GetClass()->GetName()
         );
    }
 }
more ▼

answered Apr 15 '16 at 01:13 PM

avatar image

Arthur Khusnutdinov
605 89 95 250

(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