How To Add Items To Array Variable in Editor From Blueprints ConstructionScript? Vice Versa.

[TABLE]

Hello UE4 C++/Blueprints Gurus,

		We're seeking C++ / Blueprints   recommendations To Add Items To Array Variable in Editor From Blueprints ConstructionScript? Vice Versa.

		The goal is to Add Array Items and programmatically data-fill from BP ConstructionScript, displayed in the Editor Details Panel for Manual Editing at design-time. Vice Versa.

		Thank you for reading our post. All support in this matter is greatly appreciated.

Hello there @TheGameDevStore could you elaborate more on exactly what it is you want to achieve? You can dynamically build the individual items using a “Make” node for their type. The screenshot below shows some simple examples for adding items to an array from blueprint.


https://forums.unrealengine.com/core/image/gif;base64

Sadly the items you add to an Array in the blueprint constructor won’t show up in the details panel. However if you add them in your C++ constructor they will. Alternatively you could also get and edit the array elements individually by index using the OnBeginPlay Event in your blueprint graph, so you can set them up there instead of in the details panel, but of course they’ll only be applied when the level loads.

Hello @Noxxie

We truly appreciate you taking time to respond. The intent is to dynamic build the Array List of Structures (12 members) from Mesh Skeleton at design time using the ConstructionScript, and modify parameters (if needed) from the Editor’s Detail Panel (GUI). Dynamic generation is desired as Skeletal Mesh can be changed and vary in number of bones.

With consideration to the statement: *Sadly the items you add to an Array in the blueprint constructor won’t show up in the details panel. However if you add them in your C++ constructor they will. *We will attempt to dynamically generate from C++ Constructor.

Sincere Thanks.

You’re very welcome. I’ve written a quick example for you, hope it’s of some use. :slight_smile:

MyObject.h



#pragma once

#include "CoreMinimal.h"
#include "MyObject.generated.h"

USTRUCT(BlueprintType) // We use the BlueprintType Tag to allow us to use this struct in BP
struct FMyStruct
{
    GENERATED_BODY()

   /* The EditAnywhere tag allows us to change this variable in the details panel.
    * BlueprintReadWrite just allows us to work with this variable in the Blueprint Graph */
   UPROPERTY(EditAnywhere, BlueprintReadWrite)
   float MyFloat;
   UPROPERTY(EditAnywhere, BlueprintReadWrite)
   int MyInteger;

   /* Default Struct Constructor */
   FMyStruct()
   {
       MyFloat = 0.0f;
       MyInteger = 0;
   }

   /* Regular Struct Constructor */
   FMyStruct(const float InFloat, const int InInt)
   {
        MyFloat = InFloat;
        MyInteger = InInt;
    }
};

/* Blueprintable allows us to create Blueprint classes dervived from this one */
UCLASS(Blueprintable, BlueprintType)
class EDITORWORKSPACE_API UMyObject : public UObject
{
    GENERATED_BODY()

public:

    /* Class constructor */
    UMyObject();

    /* Here's our TArray of our struct type */
    UPROPERTY(EditAnywhere, BlueprintReadWrite)
    TArray<FMyStruct> MyArray;
};


MyObject.cpp



#include "MyObject.h"

UMyObject::UMyObject()
{
    MyArray.Add(FMyStruct(5.0f, 10));
    MyArray.Add(FMyStruct(100.0f, 50));
}


The two items added in the C++ constructor being displayed in the Details panel, with their set values.

In Blueprints

When you use the “Add” node on an array variable in a Blueprint, you’re adding an element directly to that array. There’s no need to reassign the array to the variable because Blueprints operate on the principle of reference types for arrays. The variable that holds the array already points to the location of the array, so any modifications to the array are automatically reflected in the variable.


So in this case above, there is a variable being set as an array. In our case…once this object is checked as valid, it is then added to the array using the “Add (Array)” node. The variable is then being called for the following node and it has the object we just added previously, because the array was updated and the variable points to that particular array, therefore the variable is up to date.