[SOLUTION] List all properties/variables (and their values) of an object

Mark Drew asked on Twitter:

I couldn’t find an out-of-the box way of doing that in blueprints, but it’s not a lot of code to do in C++ which you can then expose to blueprints.

It’s easiest to just make a function, we’ll call it GetAllPopertiesAndValuesOfObject, which returns a TMap<FName, FString> where the map’s keys are the names of the properties.

Simply add these source files to your project. Remember to replace YOURMODULENAME_API with the name of your own module’s name, or just remove it if you only have one module (most smaller projects).

PropertyFunctionLibrary.h

#pragma once

#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "PropertyFunctionLibrary.generated.h"

UCLASS()
class YOURMODULENAME_API UPropertyFunctionLibrary : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()

public:
	UFUNCTION(BlueprintCallable)
	static TMap<FName, FString> GetAllPopertiesAndValuesOfObject(UObject* Object);
};

PropertyFunctionLibrary.cpp

#include "PropertyFunctionLibrary.h"

TMap<FName, FString> UPropertyFunctionLibrary::GetAllPopertiesAndValuesOfObject(UObject* Object)
{
	TMap<FName, FString> AllVariables;

	if (!IsValid(Object)) return AllVariables;

	for (TFieldIterator<FProperty> PropertyIt(Object->GetClass(), EFieldIteratorFlags::ExcludeSuper); PropertyIt; ++PropertyIt)
	{
		FProperty* Property = *PropertyIt;

		// No properties of "Object" type, we only want properties with value data.
		if (Property->IsA<FObjectProperty>()) continue;
		
		FString ValueText;
		if (Property->ExportText_InContainer(0, ValueText, Object, Object, Object, PPF_None))
		{
			AllVariables.Add(Property->GetFName(), ValueText);
		}
	}

	return AllVariables;
}

You can then use it like this, for example to print out all the properties and their values of an object:

5 Likes