Download

Using UE4 reflection system to extract properties of unknown types

Hello,

I’m currently writing a plugin that needs to access data from classes that it can not know at compile time.
The plugin is supposed to serve as an intermediary between two programs. One is a game design tool, the other is UE4.
In the game design tool, you can create custom object types to create what you need for your game on paper.

Now, my plugin’s goal is to make use of this data to activate certain logic that depends on those custom object types.

I thought of giving the properties certain names in the first program to identify them via reflection in my plugin’s code. However, since reflection is new to me, I don’t seem to get it right.

Basically, program A’s output writes c++ classes for me that get put into the game module’s files, to which my plugin has no access to.
However, those generated classes all inherit from classes that my plugin DOES have access to.

The members of the generated classes I either have access to or I have access to their super classes.




UProperty * prop = referencedObject->UObjectBase::GetClass()->FindPropertyByName("Dialog_Links");
        if (prop) {

            UObjectProperty * articyProp = Cast<UObjectProperty>(prop);

            UArticyObject * articyObject = Cast<UArticyObject>(articyProp->GetObjectPropertyValue(referencedObject));
}


This however crashes with the following crash message:

LogWindows: Error: Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0xffffffff
LogWindows: Error:
LogWindows: Error: [Callstack] 0x00007ffa938721c5 UE4Editor-CoreUObject.dll!UObjectBaseUtility::IsA() [d:\build++ue4\sync\engine\source\runtime\coreuobject\private\uobject\uobjectbaseutility.cpp:278]
LogWindows: Error: [Callstack] 0x00007ffa69057d0c UE4Editor-MyFirstPlugin.dll!UME_InteractableComponent::FindFirstArticyNode() [c:\users\xxx\documents\unreal projects\me_plugin_bachelor\plugins\myfirstplugin\source\myfirstplugin\private\me_interactablecomponent.cpp:83]

I guess it is because in the IsA function, GetClass can’t really return valid information since the class of the object is not known.
Is it possible for me to get the data I need if I lack the classes that contain members of classes that I DO know?

So if I had, let’s say, class “InheritedDialogue” which inherits from “BaseDialogue” (my plugin recognizes only the latter), and InheritedDialogue contained a UProperty FString, another type that my plugin recognizes: can I access that FString via reflection, and if so, how?

I did manage to get a UProperty from a class that my plugin does not know, apparent by me printing out the CppType. It’s the UProperty * prop in the code.