A fast visibility check

  • Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

Dryn

New Member
Feb 20, 2003
128
0
0
Visit site
Currently, I have a couple of effects that use a per-tick VisibleActors iterator. (Its slow, but there is a 0 fps difference for it running so I really don't care about that). However, I would be able to work out a couple additions to this effect if I stored these items it a dynamic array, and referred to them on a per-tick basis with a quick visibility check. Is there any uscript function fast enough for this purpose, and would be safe to use in a network environment? I'm not 100% sure on the speed / usage of the native function PlayerCanSeeMe(), and I would assume even a FastTrace to a dozen actors would be much slower than the iterator. As for LastRenderTime, what if the object itself is hidden with no mesh? And how do such methods effect other players present in the game; would PlayerCanSeeMe() return true if _any_ player can see the actor, or just the one on which the function was called?

Thanks in advance for your help.
 

Dryn

New Member
Feb 20, 2003
128
0
0
Visit site
Well, thats only true to a degree: LineOfSight has several instances, one being a uscript trace-pack (very slow) another being an ominous native function within the controller: native is a 95% speed boost, regardless of it being a trace or not... Also, iterators, even the trace iterators, deal with that sort of searching outside of the slow-uscript processes, and thus are faster than if I did a uscript-fasttrace to 100 actors: hence the reason for this thread in the first place; I was wondering if anyone had any hard-ish stats on the the topic.
 

Mychaeel

New Member
Dryn said:
Well, thats only true to a degree: LineOfSight has several instances, one being a uscript trace-pack (very slow) another being an ominous native function within the controller: native is a 95% speed boost, regardless of it being a trace or not...

Is that "95% speed boost" statement well-founded or just an assumption?

Traces are very expensive operations; performance differences in the way they're called should be easily outweighed by the cost of the trace itself (which is always native after all).

Did you read the Wiki page I linked to?
 

Dryn

New Member
Feb 20, 2003
128
0
0
Visit site
First, I read the page; good read. Second, the 95% is an actual figure, by Tim Sweeny, somewhere out there about the relative speeds of native code compared to uscript code. A while ago, not a recent doc, but an actual figure none the less (And I would hardly assume it would change much between engine versions, at least without any official statment of).

Also, the wiki page mentions the same speed boost, if not the number ;)

Still, the actors I have to deal with are essentially dummy actors (invisible, with no gameplay functionality) as anchors for the HUD; there are appriximately 50 or so at any given time, and about 12 or so in view on avarage. So visible actors seems to do the trick, as I only want them when a perfect LOS check works for the local camera (VisibleActors does this, if used right). Still, I can't help but feel that with a relatively limited set of these buggers, that I could do more with them if they were in an array (ie, effects when they drop out of view, etc). The only issue with that is the LOS check, and though the iterator was slow, it was only one slow item called, instead of a nested set of Trace like functions, native or otherwise. Still, though my first instinct was to go with PlayerCanSeeMe(), I've had weird returns using this function, and thus if anyone knows the details (on or offline) about it, I would really like to know.

As for the native instance of LineOfSight, this looks like the best bet (reading more into it) as it appears to be just a specialised trace, for controllers (and thus easily accessed in the hud, I hope) but spead up using the low-latency native code method. Neways, I don't have time to implement this right now, but I will try this function out, and get back to you all with how it works out.

Thanks for your intrest, and that link (a good read).
 

Mychaeel

New Member
Dryn said:
First, I read the page; good read. Second, the 95% is an actual figure, by Tim Sweeny, somewhere out there about the relative speeds of native code compared to uscript code.

It's been long known that UnrealScript code is "twenty times slower than native code." However, doing three expensive native function calls in UnrealScript code and doing one native function call that internally does the same three expensive function calls hardly makes a one-to-twenty overall performance difference because in both cases the majority of the code is executed natively.

Still, I can't help but feel that with a relatively limited set of these buggers, that I could do more with them if they were in an array (ie, effects when they drop out of view, etc). The only issue with that is the LOS check, and though the iterator was slow, it was only one slow item called, instead of a nested set of Trace like functions, native or otherwise.

The only way to find out for sure is not to speculate about it but to profile the two variants. Again, see Unreal Wiki: Optimization Techniques.

Still, though my first instinct was to go with PlayerCanSeeMe(), I've had weird returns using this function, and thus if anyone knows the details (on or offline) about it, I would really like to know.

From the source code:

Code:
/* PlayerCanSeeMe returns true if any player (server) or the local player (standalone
or client) has a line of sight to actor's location.
*/
native(532) final function bool PlayerCanSeeMe();

...so I think PlayerCanSeeMe is not the function you're looking for.