Update specific container instead of all?Solved
void GenerateMenu(BasePlayer player)
        {
            string time = GetTime();
            UpdatePlayers();
            var players = currentplayers;
            var max = maxplayers;
            var sleepers = currentsleepers;
            string bradleycol = GetBradCol();
            string helicol = GetHeliCol();
            
            
            
            var main = "box";
            var container = new CuiElementContainer();

            var panel = container.Add(new CuiPanel
            {
                Image =
                {
                    Color = "0.4 0.4 0.4 1"
                },
                
                RectTransform =
                {
                    AnchorMin = "0 0.90",
                    AnchorMax = "0.05 1"
                }
            }, "Overlay", main);


            var clockimage = new CuiElement
            {
                Name = CuiHelper.GetGuid(),
                Parent = panel,
                Components = 
                { 
                    new CuiRawImageComponent{Url = "https://i.imgur.com/cSykHxd.png"},
                    new CuiRectTransformComponent{AnchorMin = "0.1 0.80", AnchorMax = "0.25 0.92"},
                }
            };

            container.Add(clockimage);

            

            var paneltime = new CuiElement
            {
                Name = CuiHelper.GetGuid(),
                Parent = panel,
                Components =
                {
                    new CuiTextComponent{Text = time, Color = "1 1 1 1", FontSize = 10, Align = TextAnchor.MiddleCenter},
                    new CuiRectTransformComponent{AnchorMin = "0.2 0.70", AnchorMax = "1 1"},
                }
            };
            container.Add(paneltime);

            var playerimage = new CuiElement
            {
                Name = CuiHelper.GetGuid(),
                Parent = panel,
                Components =
                {
                    new CuiRawImageComponent{Url = "https://i.imgur.com/TP01GYf.png"},
                    new CuiRectTransformComponent{AnchorMin = "0.1 0.60", AnchorMax = "0.25 0.72"}
                }
            };

            container.Add(playerimage);

            var panelplayers = new CuiElement
            {
                Name = CuiHelper.GetGuid(),
                Parent = panel,
                Components =
                {
                    new CuiTextComponent{Text = $"{players}/{max}", Color = "1 1 1 1", FontSize = 10, Align = TextAnchor.MiddleCenter},
                    new CuiRectTransformComponent{AnchorMin = "0.2 0.50", AnchorMax = "1 0.85"},
                }
            };
            container.Add(panelplayers);

            var sleeperimage = new CuiElement
            {
                Name = CuiHelper.GetGuid(),
                Parent = panel,
                Components =
                {
                    new CuiRawImageComponent{Url = "https://i.imgur.com/spdF7sR.png"},
                    new CuiRectTransformComponent{AnchorMin = "0.1 0.40", AnchorMax = "0.25 0.52"}
                }
            };

            container.Add(sleeperimage);

            var panelsleepers = new CuiElement
            {
                Name = CuiHelper.GetGuid(),
                Parent = panel,
                Components =
                {
                    new CuiTextComponent{Text = sleepers.ToString(), Color = "1 1 1 1", FontSize = 10, Align = TextAnchor.MiddleCenter},
                    new CuiRectTransformComponent{AnchorMin = "0.2 0.30", AnchorMax = "1 0.65"},
                }
            };
            container.Add(panelsleepers);


            var bradleyimage = new CuiElement
            {
                Name = CuiHelper.GetGuid(),
                Parent = panel,
                Components =
                {
                    new CuiRawImageComponent{Url = "https://i.imgur.com/VrYPrKI.png", Color = bradleycol},
                    new CuiRectTransformComponent{AnchorMin = "0.1 0.15", AnchorMax = "0.30 0.32"}
                }
            };

            container.Add(bradleyimage);

            var heliimage = new CuiElement
            {
                Name = CuiHelper.GetGuid(),
                Parent = panel,
                Components =
                {
                    new CuiRawImageComponent{Url = "https://i.imgur.com/hTTyTTx.png", Color = helicol},
                    new CuiRectTransformComponent{AnchorMin = "0.4 0.15", AnchorMax = "0.60 0.32"}
                }
            };

            container.Add(heliimage);
        
            CuiHelper.AddUi(player, container);

            

        }

        
        void MakeMenu(BasePlayer player)
        {
            GenerateMenu(player);
        }

        void DestroyMenu(BasePlayer player)
        {
            CuiHelper.DestroyUi(player, "box");
        }

        void UpdateUI(BasePlayer player)
        {
            DestroyMenu(player);
            MakeMenu(player);
        }

I have this ui and in it there is a clock that displays the current in game time. I need this to refresh every 4.5 seconds. I did that by adding a timer to excecute the updateui function. However as the ui has pictures, when it refreshes every 4.5 seconds, the pictures lag the ui. I want to make it so just the clock text (paneltime) updates, but I have no clue how to go about it. Can anybody help me?

Instead of giving the clock panel a guid, give it a unique name like "MyUniqueUI.BradleyClock". When you want to update just the clock, destroy and recreate just the clock panel by name.

yeEF718FTqzlQM7.jpg WhiteThunder

Instead of giving the clock panel a guid, give it a unique name like "MyUniqueUI.BradleyClock". When you want to update just the clock, destroy and recreate just the clock panel by name.

void OnServerInitialized()
        {
            timer.Every(4.5f, () =>
            {
                UpdateTime();
                foreach(BasePlayer player in BasePlayer.activePlayerList)
                {
                    CuiHelper.DestroyUi(player, "clock.time");
                    CuiHelper.AddUi(player, "clock.time");
                }
            });
        }

var paneltime = new CuiElement
            {
                
                Name = "clock.time",
                Parent = panel,
                Components =
                {
                    new CuiTextComponent{Text = time, Color = "1 1 1 1", FontSize = 10, Align = TextAnchor.MiddleCenter},
                    new CuiRectTransformComponent{AnchorMin = "0.2 0.70", AnchorMax = "1 1"},
                }
            };

            container.Add(paneltime);

I did this and it doesnt work, the time doesn't show up on the ui anymore. What did I do wrong?

The way I've done it before is to create a new CuiElementContainer each time, add the element to it, then send that with CuiHelper.AddUi(player, container).

9vTS7WQEgl9DlRp.jpg WhiteThunder

The way I've done it before is to create a new CuiElementContainer each time, add the element to it, then send that with CuiHelper.AddUi(player, container).

I can't get that to work either, thanks for your help though.

qmjN1cJ8KfMuBPP.jpg WhiteThunder

The way I've done it before is to create a new CuiElementContainer each time, add the element to it, then send that with CuiHelper.AddUi(player, container).

Nevermind, I made a new container for the images and then added them on at a different time, that worked fine. Thanks again for your help.

Locked automatically