Download

C++ Reflections and a simple Interpreter

Hi. I need to write a simple interpreter in c++ for my game, but I’m having trouble understanding the documentation (which is lacking).

How do I get and set a values of a UProperty for an object?
How do I invoke methods of an object?
How do I pass a “list” of arguments for the method?
How do I get the return value of the method?
Can I find/get a property or method by name (string)?

Thanks.

No one ever worked with Unreal’s reflection system? cough bump cough

I think the reason why no one answer your questions are, those are pretty basic questions, and you can get the answers easily by digging into the source code?

If it worked like that, then no one would ever come here to ask questions. Instead of wasting your arrogance on strangers you could post something useful.

Nope, you should try your best to find the answers yourself before coming here to beg for an answer, especially for this kind of pretty basic question.
You should not only read the documentation, which is pretty limited, but also dig into the source code. The reflection system in Unreal Engine is pretty amazing and you can learn a lot by browsing the engine source.

Hi OtherDude

Did you see this blog post about Unreal Property System?

I’ve already read that post and it wasn’t very helpful.

The interpreter and virtual machine are already done. The only thing left to do is hook it up with the reflection system so I can change UObject field values and invoke functions.

I was looking into the reflection system, but I can’t find a way to use it correctly. To retrieve a UObject function I’m doing something like this:


UFunction* func = myUObject->FindFunction("someFunction");
func->Invoke(myUobject, ..., ...);

But I don’t know what to pass as the second (FFrame) and third (void*) arguments.

For the UObject field values I’m trying to use something like:


UProperty* prop = myUObject->GetClass()->FindPropertyByName("someProperty");

But I don’t know how to change the actual value of the variable.

Any ideas?

Take a look at the ScriptPlugin, specifically the ScriptGeneratorPlugin that generates wrappers that call UObject functions with parameters. You may find this thread useful.