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"

Set UPROPERTY specifiers for members of TArray

Is it possible to set UPROPERTY specifiers for TArray members (derived from UObject)?

 UPROPERTY()
 TArray<UArrayMember*> classAttribute;

I'd like to have instances of UArrayMember (created with NewObject()) to be recognized as UPROPERTY(EditAnywhere) to be able to edit its exposed attributes in the Unreal editor.

At least the Garbage Collector might recognize UArrayMember according to the documentation:

TArrays have the added benefit of having their elements garbage collected. This assumes that the TArray is marked as a UPROPERTY, and that it stores UObject derived pointers.

but when using UArrayMember inside TArray I'm not able to set UPROPERTY specifiers. So I've tried using a struct as wrapper:

 USTRUCT()
 struct FArrayMemberWrapper
 {
     GENERATED_BODY()
 public:
     UPROPERTY(EditAnywhere, BlueprintReadWrite)
     UArrayMember* arrayMember;
 
     /*! For Garbage Collector.
     */
     void Destroy() {
         arrayMember = nullptr;
     }

     FArrayMemberWrapper() : arrayMember(nullptr) {}
 };

and using instances of the struct in TArray of my AActor derived class:

 UPROPERTY()
  TArray<FArrayMemberWrapper> structContainerForArrayMember;
 

However when clicking on the instance of UArrayMember then the UE4 editor still shows Native components are editable when declared as a property in c++, so the attributes are not editable. Does anyone have an idea what I'm doing wrong?

Nonsense idea

've also tried the idea written here,

 UPROPERTY()
 UArrayMember* test;
 UPROPERTY()
 TArray<UArrayMember*> classAttribute;

but as expected the instances of UArrayMember are not recognized as UPROPERTY by Unreal editor as well (since there is no connection between test and members of classAttribute).

Product Version: UE 4.14
Tags:
more ▼

asked Feb 12 '17 at 10:29 PM in C++ Programming

avatar image

Roi Danton
72 10 16 16

avatar image Reflection Rip Jul 23 '18 at 06:47 PM

I know this is an oldie, but I am wondering how to do the same thing. I have an array of bytes (uint8) and wanted to add the meta property 'NoSpinbox = true' to each item. The spin box covers up the last digit on my editor, making the numbers unreadable.

My current solution:

 USTRUCT(BlueprintType)
 struct Fuint8
 {
     GENERATED_BODY()

     UPROPERTY(BlueprintReadOnly, VisibleAnywhere, Transient, Category = "Data File", meta = (NoSpinbox = true))

     uint8 Data;
 };

 USTRUCT(BlueprintType)
 struct FTreeBlockStructure
 {
     GENERATED_BODY()

     UPROPERTY(BlueprintReadOnly, VisibleAnywhere, Transient, Category = "Data File")
     FString Name;

     UPROPERTY(BlueprintReadOnly, VisibleAnywhere, Transient, Category = "Data File", meta = (NoSpinbox = true))
     int32 Size;

     UPROPERTY(BlueprintReadOnly, VisibleAnywhere, Transient, Category = "Data File")
     TArray<Fuint8> Data;
 };

 void AMyFileActor::ReadData(char* cDataFileName)
 {
     char* ReadData;
     ReadData = (char*)malloc(FileData.Size + 1);
     myFile.read(ReadData, FileData.Size);
     for (int j = 0; j < FileData.Size; j++)
     {
         Fuint8 newChar;
         newChar.Data = ptro[j];
         FileData.Data.Add(newChar);
     }
 }

This works, but it's not ideal. I need to add a new element to my data structure. So now instead of FileData.Data[i], I need to have FileData.Data[i].Data. And I can't just fill the array with Append, I need a for loop and add each element manually.

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

1 answer: sort voted first

I was on the right track using an UStruct() as wrapper. I've just looked at the wrong place for editing its attributes in Unreal Editor.

Instead of selecting UArrayMemberComponentName (Inherited) in the details panel, I have to expand the TArray of the AActor(Instance) to be able to edit the attributes of UArrayMember.

I'm just wondering why this distinction is made by Unreal Editor because both ways of "views" in the details panel are pointing to the same object (I've tested it with modifying attributes values and the change was reflected when clicking on UArrayMemberComponentName (Inherited), too).

more ▼

answered Feb 15 '17 at 08:16 PM

avatar image

Roi Danton
72 10 16 16

(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