How can I Access my C++ array inside a blueprint?

Hey

I made an array filled with dynamically updated data inside C++, and I need a way to access it inside the event graph of my HUD blueprint.

Is there anyway to do such a task?? I’d hate to have to re-code the whole thing in blueprint.

Thanks

In general you can either expose the array as a UPROPERTY or make a blueprint callable UFUNCTION that returns the array to the blueprint.

The array of data will need to be of a type that can be accessed in C++, but it is certainly doable, but without knowing more about where the array is stored and the type of data contained in it I can’t give you a better answer.

I tried exposing the array as a UPROPERTY but I still couldn’t find it.

The array is a an array of custom struct objects located in my custom game mode class.

Here are the codes:

USTRUCT()
struct FMapPosition
{
	GENERATED_USTRUCT_BODY()

	FString Name;
	float AngleToEnemy;
	float Distance;
};

UCLASS(BlueprintType, Blueprintable)
class AAORGameGameMode : public AGameMode
{
	GENERATED_UCLASS_BODY()

public:

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = HUD)
	TArray<FMapPosition> MapPositions;
};

First thing you’ll need to do is mark the USTRUCT as a BlueprintType, otherwise Blueprints will not know anything about it.

Second, you’ll need to mark each of the properties you want to be able to access in Blueprints as a UPROPERTY (probably BlueprintRead unless you want blueprints to be able to write to them, same with MapPositions).

Finally, once you’re in the HUD you should be able to simply call Get Game Mode … cast it to your GameMode subclass, and access the variable and those properties.

Thank you very much for the speedy reply, but unfortunately it didn’t work.
I can’t see anything related to map positions in blueprint

Here are the updated codes:

USTRUCT(BlueprintType, Blueprintable)
struct FMapPosition
{
	GENERATED_USTRUCT_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = HUD)
	FString Name;
	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = HUD)
	float AngleToEnemy;
	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = HUD)
	float Distance;
};

UCLASS(BlueprintType, Blueprintable)
class AAORGameGameMode : public AGameMode
{
	GENERATED_UCLASS_BODY()

public:

	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = HUD)
	TArray<FMapPosition> MapPositions;
};

I took your struct and property definition and dropped them in to QAGameMode to quickly test it and it looks like it works how I would expect it to.

This chunk of Blueprint I dropped in to a HUD blueprint once I compiled up with your definitions.

Make sure you are casting to your GameMode class and then from that As pin when you drag off searching Map Positions should find you your variable.

Also, while it won’t hurt (probably just ignored by compiler), you don’t need to mark your struct as Blueprintable.

EDIT (sort of): tried to fix missing don’t, mis-clicked and accidentally deleted post, had to recreate it, thankfully it was still on clipboard … dear AnswerHub, confirm delete please, kthxbye

I really don’t know why it won’t work. I’ll try again.
Could you please repost the blueprint image you just uploaded. It is not loading.

EDIT: It worked!!! The trick was to remove the “Blueprintable” modifier from the struct definition.

Thanks a lot Marc

Ok. This is weird.
It worked when I had the “DebugEditor” build, but completely crashed and couldn’t recognize FMapPositions struct when I ran it straight from the editor (Not from VS2013).

Any idea what might have caused this??

EDIT: I just had to rebuild using “DevelopmentEditor” configuration, and it worked. Thanks for the support, Marc :slight_smile: