How to make actor react to being outside viewport

I would like to do something fun. :smiley:

I’d like to make an object vanish when you stop looking at it. More specifically, I want to make a room with a series of doors. Each door is locked. However when you look away from the door, the door is gone when you look back.

How would I make the door vanish and replace it with a section of wall. It’d probably involve setting the visibility of the door to false and the wall part to true, but how would I make it react to being outside the viewport?

There are a few ways to detect if an actor is visible, but I believe both ways require C++ to do.

  1. Each actor stores the last time it was rendered. AActor::GetLastRenderTime(). If the last time it was drawn is > than ~1 frame (eg. 1/60 if 60fps is your expected frame rate), then it is not currently visible.
  2. You can build the view frustum from the local scene view and directly test if it is within the frustum bounds.

2 is more accurate, but 1 is much easier and often more than enough. In either case though, you’d need to test the object at a reasonable rate for accuracy and performance.

I was really hoping to avoid hard coding, but I guess I gotta learn someday.

Though it dawns on me. I may be able to use Get Control Rotation in blueprints to indicate when the camera is angled away from the door. I’ll try that. Thank you, anyways!