I want to know whether a system I can implement might be more performance efficient than a built-in function/object or not. And to know this, I need to know how that function/object operates behind the scenes.
For example, do we know how ClickDetector works behind the scenes, does Roblox share this information?
Does it cast a ray to know if the player is hovering over the object, and check the player’s distance to the object every frame?
If so, If I use the exact same code to achieve the same result, would Roblox’s built-in function would still be more performance efficient, because it works not on Lua but on C++?
More precisely
I currently want to make a distance detection, and I thought of two ways of implementing this;
-
Use ProximityPrompt’s PromptShown event to detect when the player gets close.
-
Check the distance between the player and every interactable object every heartbeat
Now, the second method is more flexible and optimizable. Like finding the closest interactables every X interval and only checking the distance of those objects from the player.
But do I really need to go into all that trouble for optimizing, or the ProximityPrompt already does a good job at keeping massive amounts of objects optimized?
This example can be used for most other objects/functions. So I request a more general answer rather than a direct answer to this example I gave.