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, BlueprintOnly, 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.

Thanks and Regards,
Sameek Kundu

#Solution

Change your header from

UPROPERTY(EditAnywhere, BlueprintOnly, Category = "Road Placeholders", Meta = (MakeEditWidget = true))

to

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Road Placeholders")

Now in BP you can still use the Get node but you will not see Set.

In C++ you can still do whatever you want :slight_smile:

Does this work for you?

#:heart:

Rama

Hi Rama,

But in this case the user wont be able to drag the vector variables in the desired direction within the editor. What I want is for theu ser to change the values of the vector variables , but the plus button next to an array , for adding new elements , and the deleting of existing elements should not work.

It is just a road construction automation , an array contains two vectors present at each side of every road branch , and the user can drag those vectors to create new road branch , if the user delete one vector from the array then he will not be able to create branch at that section.

I am not using any Blueprint , it is 100% C++ implementation , i am dragging directly from the class viewer , the user has to make changes in the object property window itself. There only i want this functionality.

I don’t believe what you are asking for is possible for dynamic arrays. Properties can be visible (no edit) or editable (defaults only, instance only, anywhere). In the case of the dynamic array, the whole of the array is editable or visible. However, you can use static arrays where you specify the size at compile time.

Maybe late, but you can do that with EditFixedSize

ex.
UPROPERTY(EditAnywhere, EditFixedSize, Category = “MyCatNotDog”)
TArray RCTBranchesTop;

1 Like