blented
(blented)
1
Is there a way via the Python API to list all editor properties of a given object?
I found this for UObjects in c++ but couldn’t find a corresponding class or methodology in the Python docs:
Without such a method there doesn’t seem to be a good way to figure out what you can set via set_editor_property()
Good morning,
I did not find any possible way to do it in Python only, but here is the way I’m doing it using C++
.h
#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "CppLib.generated.h"
UCLASS()
class UNREALPYTHONPROJECT_API UCppLib : public UBlueprintFunctionLibrary {
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable, Category = "Unreal Python")
static TArray<FString> GetAllProperties(UClass* Class);
};
.cpp
#include "CppLib.h"
#include "Runtime/CoreUObject/Public/UObject/UnrealType.h"
TArray<FString> UCppLib::GetAllProperties(UClass* Class) {
TArray<FString> Ret;
if (Class != nullptr) {
for (TFieldIterator<UProperty> It(Class); It; ++It) {
UProperty* Property = *It;
if (Property->HasAnyPropertyFlags(EPropertyFlags::CPF_Edit)) {
Ret.Add(Property->GetName());
}
}
}
return Ret;
}
And then in python:
import unreal
my_python_object = unreal.StaticMesh()
my_object_properties = unreal.CppLib.get_all_properties(my_python_object.get_class())
print my_object_properties
Running into a trove of issues trying to recreate this, among them this.
... 'UMyClass' uses undefined class 'UNREALPYTHONPROJECT_API' ProjName $ProjPath\MyClass.h 6
Besides a barrage from Visual Studio complaining about Syntax error with missing ‘;’ after UCLASS() etc…
Had to alter the Atomic.h as well seeing it was complaining about a missing ‘)’ and found others having same issue
My full code is currently
#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "MyClass.generated.h"
UCLASS()
class UNREALPYTHONPROJECT_API UMyClass : public UBlueprintFunctionLibrary {
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable, Category = "Unreal Python")
static TArray<FString> GetAllProperties(UClass* Class);
};
MyClass.h
#include "MyClass.h"
#include "Runtime/CoreUObject/Public/UObject/UnrealType.h"
TArray<FString> UMyClass::GetAllProperties(UClass* Class) {
TArray<FString> Ret;
if (Class != nullptr) {
for (TFieldIterator<UProperty> It(Class); It; ++It) {
UProperty* Property = *It;
if (Property->HasAnyPropertyFlags(EPropertyFlags::CPF_Edit)) {
Ret.Add(Property->GetName());
}
}
}
return Ret;
}
MyClass.cpp
Any idea what I’m missing?
1 Like
darkczar
(darkczar)
5
This works great, thanks! Just a head’s up - in UE4.25 (or earlier) UPROPERTY has changed to FPROPERTY - VS2017 compiler complained.