How to pass an Object param into ProcessEvent

When you’re passing a single parameter (other than “this”) you can pass it directly as a pointer (e.g. &bVisible) and it will work.

If you need to pass “this” (because c++ won’t let you pass “&this”), or if you are passing multiple parameters, and/or if you are accessing a return value you can do something like this:

//define a container
struct FDynamicArgs
{
    float Arg01 = 100.0f;
    AActor* Arg02 = NULL;
    float Return = 0.0f;
};

//create the container
FDynamicArgs Args = FDynamicArgs();

//You must assign "this" outside the generic struct, 
//or within the struct's context "this" will refer to the
//struct itself.
//Alternatively, you can create a construction method
//for the struct and pass "this" as an argument there
Args.Arg02 = this;

//then pass the container by reference, along with the function pointer
TargetObject->ProcessEvent(TargetMethod, &Args);

You can also create a predefined struct (or other container object) elsewhere rather than dynamically defining it here.

Arguments are parsed by type in the order assigned.

Any trailing parameters of the appropriate type will be assigned the return value (if any).

Bear in mind that your container and any contained values will only exist for the life of the method they are created within; so if you need the return value outside this method you’ll need to preserve it somehow (assign to a referenced argument, return the value, etc.).

4 Likes