I'm trying to create a custom UI for a plugin and on Unload() I'm trying to cycle through all players and delete the container. However, I'm getting Disconnected with an RPC Error - I'm thinking this happens when attempting to destroy an element that doesn't exist?
What is the safe or proper way to try and delete an element on all players? Do I need to create a dictionary or something that tracks the status of the UI for each connected player?
Solved Safely destroying CUI?
Discussion in 'Rust Development' started by Mheetu, Aug 9, 2017.
-
foreach(var player in BasePlayer.activePlayerList)
CuiHelper.DestroyUi(player, “ui parent name here”); -
That's essentially what I already have... isn't it? When it's just me in the server and the UI is visible, this (below) removes it correctly. If the UI doesn't exist and it tries to unload, I get disconnected with that RPC Error...
Code:private void Unload() { for (int i = 0; i < BasePlayer.activePlayerList.Count; i++) { DestroyUi(BasePlayer.activePlayerList[i], uiName); } }
-
What’s your DestroyUi method?
Never known there to be an RPC error when removing a UI -
Literally just a shorter method name at this point, will probably rename it and add the destruction of timers to it later... haven't gotten that far yet though.
Code:private void DestroyUi(BasePlayer player, string name) { CuiHelper.DestroyUi(player, name); }
-
Maybe try destroying another element that isn’t your main parent?
Not quite sure -
Not sure if it helps any, but this is the red error message that appears in the top-left of the client when I'm disconnected.
Code:NETRCV_ReadBytes returned falseNullReferenceException: Object reference not set to an instance of an object Facepunch.Network.Raknet.Peer.ReadUInt32 () Facepunch.Network.Raknet.StreamRead.UInt32 () Network.Read.MemoryStreamWithSize () Network.Read.String () (wrapper remoting-invoke-with-check) Network.Read:String () CommunityEntity.DestroyUI (RPCMessage msg) CommunityEntity.OnRpcMessage (.BasePlayer player, UInt32 rpc, Network.Message msg) UnityEngine.Debug:LogException(Exception) CommunityEntity:OnRpcMessage(BasePlayer, UInt32, Message) BaseEntity:CL_RPCMessage(UInt32, UInt64, Message) Client:OnRPCMessage(Message) Client:OnNetworkMessage(Message) Facepunch.Network.Taknet.Client:HandleMessage() Facepunch.Network.Raknet.Client:Cycle() Client:Update()
Code:uiName = elements.Add(new CuiPanel [...]
Last edited by a moderator: Aug 9, 2017 -
Ahhh, yea.
Good find