How to prevent user to add new elements or delete elements from an array?

Hi ,

I am using Editanywhere within UPROPERTY to make my vector array editable , as shown below :

UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Road Placeholders", Meta = (MakeEditWidget = true)) 
TArray<FVector> RCTBranchesTop;

Now user can definitely modify each vector of the array, but there will be two elements in the array , and user cannot cannot add or delete these two elements from the editor. They will be manipulated only in the code. How do I prevent user from adding elements in this array or removing the existing elements ?

One more issue I saw , when I am changing the value of the vectors from the editor , onpropertychanged property is getting fired but the property name is coming as null :

UProperty* PropertyThatChanged = PropertyChangedEvent.Property;
 FName PropertyName = PropertyThatChanged != NULL ? PropertyThatChanged->GetFName() : NAME_None;

so I am unable to apply any condition which determined which property ha been changed, and I have to write my propertychange logic in within “else {}”. So for every vector i have declared , the condition present under ELSE is getting fired.

Kindly help.

Can you not just add the two ‘read only’ elements at runtime? that way they can not be accessed?

No actually every thing has to take place in class construction itself, and user should be able to view the changes in the editor without having to hit play button. This is what I want

when you create an array of elements in BP/ C++ and make them editable in property window, you can do three things
1>Add elemets to the array
2>Delete elements from the array
3>Modify the existing elements of the array

I only want to do the third one , i want addition and deletion of elements inacccessible from the editor property window.

If your array has a fixed size, then make it a static array:

UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Road Placeholders", Meta = (MakeEditWidget = true)) 
FVector RCTBranchesTop[2];

If you absolutely want to use a TArray, the EditFixedSize keyword might also help:

UPROPERTY(EditAnywhere, EditFixedSize, BlueprintReadOnly, Category = "Road Placeholders", Meta = (MakeEditWidget = true)) 
TArray<FVector> RCTBranchesTop;

As for PostEditChangeProperty, it might not be sufficient to watch “inner” properties such as the contents of an array. (I know for sure it’s not appropriate for struct members.) PostEditChangeChainProperty is a more advanced callback you can use that will also give you the property chain leading to the element you are editing. You then can walk up the property chain to see if the inner property being edited is part of RCTBranchesTop.


P.S.: As added fluff, a very obscure behaviour of static array uproperties is you can view them with names instead of indices. For instance, suppose the contents of RCTBranchesTop are “left” and “right” for 0 and 1…

enum RCTBranchTypes
	RCTBranchTypes_MAX UMETA(Hidden)

UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Road Placeholders", Meta = (MakeEditWidget = true)) 
FVector RCTBranchesTop[RCTBranchTypes_MAX];

This might be useful to you.

Wow , that is an excellent alternative you have provided.
Will try this right away.

Thanks a lot