Is it a bad practice to update the UI every frame?

I will need to use some functions to update the UI every frame already. My main debate here is wether or not I should have other sorts of events instead of the RenderStepped on the unecessary stuff.

As an example I will need to make a map UI similar to that of GTA and I still need to update a timer.

1 Like

RenderStepped is fine up to a point. You want anything in the event to finish within the framerate, so don’t do anything ridiculous like terrain generation every single frame. You’ll probably be fine.

1 Like

try to not think of it as bad practice

at the end of the day there is something you want to do and if that something requires you to update the gui every frame then you have no choice but to do it

but lets say the gui is not changing but your still updating it every frame well then your doing it for nothing and there is no point updating every frame

if you only need to update when the Camera.Focus moves then you can do something like this

local camera = workspace.CurrentCamera
local mapPosition = Vector3.new(0, math.huge, 0)

camera:GetPropertyChangedSignal("Focus"):Connect(function()
    -- get how far the camera has moved since the last time the map was updated
    local magnitude = (camera.Focus.Position - mapPosition).Magnitude

    -- if the distance is less then 4 studs do nothing
    if magnitude < 4 then return end

    -- if the distance is grater the 4 studs then update the positon
    mapPosition = camera.Focus.Position

    -- and now lets update the map
    UpdateMap()
end)

so here you can see we have no loops we are waiting for the camera focus property to change this might happen every frame it might not happen every frame and then we have a 4 stud margin so that we have to move at least 4 studs before the map is updated

5 Likes

For a timer, I would only update it every increment of the timer instead of every frame. (If the timer’s smallest measurement is seconds, only update it every second.)

The only bad practice from utilizing RenderStepped is if you have a huge list of loops and/or tasks to complete. (If your map is UI generated with a custom function, obviously you don’t want the map generation function in your RenderStepped connection.)

Since you’re doing stuff per frame, you typically want to restrict it to the least amount of tasks as possible as to not hinder performance. If you don’t need it updated every frame, you should bind the map’s position/rotation function to any change in character position/specific camera properties like 5uphi said.

Applying changes to something that doesn’t need to be changed could potentially eat up resources when they could be spent elsewhere. In terms of performance, it’s always better practice to perform actions based on necessity instead of opportunity.

2 Likes