Hi people, Hope you’re doing good, I want to print a string of the actors currently visible on the screen and as soon as they go away I want to stop printing the string. How can I achieve this functionality?
in Blueprints there is IsRecentlyRendered() (based on a StaticMesh) it takes in a time since it was last rendered.
most everything in Blueprints can also be done in C++
though this method would usually be the Actor running the function on itself, or being done in some kind of Manager.
if you want this to be done from say the the Player, then you could accomplish this through like a sphereTrace, but keep in mind that the Camera Frustum is angled convexly so would need to account for the angle difference, maybe by doing some math with cosine to figure out if it is in the frustum.
though you could have the Pawn hold a bool for if it isRecentlyRendered()
then have your manager get that list.
Keep in mind that RecentlyRendered accounts for all cameras in your level, so for multiplayer the cameras of the other players would also count.
Alright, so how about avoiding the multiplayer issue? What to be done then?
where is this being done from? (the player, a manager that knows of the Actors or concern, some random Actor object)
and what are you attempting to accomplish? (you might be able to accomplish it without figuring out if the actor was rendered or not)
I’m doing it in Player Controller. I’m trying to lock on a enemy target but when that enemy leaves the screen we should no longer be locking that target. Is this clear to you now?
first we want to get the other Actor
s transform
GetActorsOfClass
(which is kind of slow as it has to sift through everyActor
in theWorld
),- throwing like a Sphere Trace into the world on a key press, but this has the issue of the game window not being a circle, and takes no account for the angle of the sides, top, and bottom of the frustum.
- A manager (that exists to hold all the
Actor
s you will actually care about, introducing the overhead of needing to store say aTArray<[MyPawnClass]>
, and thoseMyPawnClass
needs to be registered somehow, but the list just exists when we need it), - Technically the most expensive middle ground being put a collider on the
Player
that only interacts with the things we care about (this would require playing around with collision channels, and is limited to Isometric perspectives like top down, or side view) - For other perspectives especially where the camera can rotate put the collider on the Camera itself ( this would probably require rolling your own collider to mimic the behavior of a frustum and would need to be modified if say the zoom level “needs to”/“Can” be changed)
The collider method is the simplest as no math is needed just managing the OnBeginOverlap
and OnEndOverlap
but has the cost of taking up collision channels, the feedback being on the During_Physics_Tick_Group
, and having the engine need to be monitoring the collider for the overlaps.
for the Manager or the GetActorsOfClass you can look here Perform Frustum Check there is a C++ and a blueprint implementation that both look promising.
Thanks Man,