Get viewport instance and receive OnDrawn event?

Hey all,

Anyone have an example of how I can:

  1. Get a reference to the Viewport instance
  2. Bind a function to the OnDrawn delegate so that I can receive an event when the Viewport is drawing a frame?

The reason I am looking to do this is I need to implement some custom screenshot code because the built in screenshot code in the engine appears to be very hard coded, and I can’t find a way to do what we need without making engine changes which I would rather avoid if possible.

So I managed to bind, I think, like this:

GetWorld()->GetGameViewport()->OnDrawn().AddUObject(this, &AMyActor::FrameDrawn)

However when I try to use this, I get an access violation when the delegate tries to add the instance. In AddDelegateInstance there is code that is supposed to check if the function is already bound, and this just crashes.