SButton And SBorder Arrays in C++

I am trying to create an array of SButton and an array of SBorder in C++. This is so that arrays do not have to be constantly made in Blueprint, they can just be accessed (see attachment) as they never change. Below is the code that I use to try and make the arrays, but when it compiles it says “Unrecognized type ‘SButton’” and "C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.MakeFile.Targets(38,5): error MSB3073: The command ““C:\Program Files\Unreal Engine\4.5\Engine\Build\BatchFiles\Build.bat” GESGameEditor Win64 DebugGame”

In the .Build.cs:

PublicDependencyModuleNames.AddRange(new string] { "Core", "CoreUObject", "Engine", "InputCore", "Slate", "SlateCore" });

In the .h I want it in:

#include "Slate.h"
#include "SBorder.h"
#include "SButton.h"

UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "UMG")
      TArray<SButton> ButtonArray;

UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "UMG")
      TArray<SBorder> BorderArray;

Any help would be appreciated, but if it is not possible it doesn’t hinder what I am doing anyway (wanted it for convenience).

I have no idea why would you want to store these widgets in arrays but I’ll try to help you anyway. I assume that PowerWidget and Gyro, Solar, Laser etc. are widgets created in UMG. If so, that means these variables are actually UWidgets, not SWidgets. I dont think that you can access SWidgets (SBorder/SButton) within blueprints. Anyway, your arrays store instances of SButton/SBorder but they should store pointers to UWidgets. So it should look like this “TArray<UButton*> ButtonArray;”, note that in this case you have to #include “UMG.h” on the top of your header file.

When you will take a look at Button.h file you will see that UButton class is actually only a container for SButton functionality that can be then accessed via UMG.

It still says “Unrecognized type ‘UButton’” when I do “TArray<UButton*> ButtonArray;” and #include “UMG.h”. I have also tried UWidget, #include ‘Button.h’ and #include ‘Widget.h’, but it makes no difference. Thank you for trying to help anyway, I don’t fully understand UMG as it is one of my team mates who is doing it. He just asked me if there was a way to store the buttons and border in an array.

Button Arrays now in 4.6.

You can definitely make TArrays of UObjects (such as UMG widgets) in versions prior to 4.6. I’ve been using widget arrays across my user widgets for more generic management of inventory lists, etc. and UMG itself uses widget TArrays in a few different places behind the scenes.

You were likely missing UMG in your Build.cs’s public dependency modules, so the header tool couldn’t recognize that UObject type when generating managed code for the array.


I did get it to work, I was on about 4.6 has it built into blueprints now.