RegisterHook

The RegisterHook registers a callback for a UFunction

Callbacks are triggered when a UFunction is executed.

The callback params are: UObject self, UFunctionParams...

Returns two ids, both of which must be passed to UnregisterHook if you want to unregister the hook.

Any UFunction that you attempt to register with RegisterHook must already exist in memory when you register it.

RegisterHook doesn't support delegate functions!

RegisterHook Parameters

#TypeInformation
1stringFull name of the UFunction to hook. Type prefix has no effect.
2functionIf UFunction path starts with /Script/: Callback to execute before the UFunction is executed.
Otherwise: Callback to execute after the UFunction is executed.
3function(optional)
If UFunction path starts with /Script/: Callback to execute after the UFunction is executed
Otherwise: Param does nothing.

RegisterHook Return Values

#TypeInformation
1integerThe PreId of the hook
2integerThe PostId of the hook

Callback Parameters

#TypeInformation
1RemoteUnrealParamObject representation of the "this"-pointer ("self" in lua) of the function, also known as "Context". It contains the object wrapped as RemoteUnrealParam that called the function.
2..NRemoteUnrealParam...All function parameters wrapped as RemoteUnrealParam

Example

PreId, PostId = RegisterHook("/Script/Engine.PlayerController:ClientRestart", function(Context, NewPawn)
    local PlayerController = Context:get()
    local Pawn = NewPawn:get()

    print(string.format("PlayerController FullName: %s\n", PlayerController:GetFullName()))
    if Pawn:IsValid() then
        print(string.format("NewPawn FullName: %s\n", Pawn:GetFullName()))
    end

    if PreId then
        -- Unhook once the function has been called
        UnregisterHook("/Script/Engine.PlayerController:ClientRestart", PreId, PostId)
    end
end)