Download

Type Safe Property Selection for Designers

Hey guys,

I’m breaking my head on how the get the designer (editor user) to select properties of a specific class via dropdown and execute some operation on it.

If you have a class like this:



UCLASS(...)
class MyClass : (...)
{
public:
	UPROPERTY(...)
	MyTypeA MyPropertyName1;

	UPROPERTY(...)
	MyTypeA MyPropertyName2;

	UPROPERTY(...)
	MyTypeA MyPropertyName3;	
};


Now I want to be able to generate a Blueprint function where there is a dropdown of the following:



MyClass.MyPropertyName1
MyClass.MyPropertyName2
MyClass.MyPropertyName3


Example of the blueprint function:



UCLASS(...)
class AccessClass : (...)
{
public:
	UFUNCTION(...)
	void DoSometing(MyClass* object, PropertyOfMyClassToBeSelectedFromDropdown);
};


The desginer can now plug in any MyClass object and select the specific property he wants to do something with (whatever that is).
Is there a way to archive this?

There is, but it’s far from straightforward.

First, you can’t do it with a regular UFUNCTION. You’ll need to create a custom node derived from UK2Node - look at the examples in the engine code, all the classes beginning with UK2Node_xxx. This is pretty heavy stuff.

Then within that node, to create your dropdown you’d make use of TFieldIterator to iterate over the properties of interest, something like


for(TFieldIterator< UProperty > It(MyClass::StaticClass()); It; ++It) { ... }

This would be a lot of work for something you could presumably achieve by just making a separate UFUNCTION to operate on each of your properties? Less scalable of course, but in this case it might be the better way to go.