What is the standard way to handle UI updates that involve creating and destroying GameObjects?
Tutorials on displaying information in the HUD, such as this one about health bars, just set the health bar's displayed value to the correct one every frame. This works nicely if I just have to watch specific numerical values.
Suppose (made up example) that I need to display a 3D chess board in the HUD.
In the game state, there is a non-Monobehaviour object that describes the state of the chessboard. In the UI, there's a 3D scene with every chess piece being a GameObject. Now, if I follow the previous scheme, and delete then recreate all the pieces according to the current game state every frame, that's going to take up a lot of overhead. I need to make it so that if, for example, just one pawn moved to a different square in the internal state of the chess board, the UI update moved the pre-existing pawn, rather than destroying and recreating.
I have some understanding of how to do that "the hard way", by introducing a separate control layer and making the class that contains the abstract representation of the chess board to send events, but I find this solution unsatisfactory. I don't want to add references to Unity events in the plain, potentially reusable C# class containing just the chess board state.
I could also make some sort of watchdog object that contains the current and the previous chess board states and calculates the most resource efficient way to get from here to there, but it can get very algorithmically hard if we extend this logic to something more complicated than a chess board.
What are some of the "standard" ways of handling HUD updates in situations like that?
Your answer
Follow this Question
Related Questions
Does using multiple World Space Canvases affect performance? 0 Answers
is there simple way to put random sprite to gameobject multi child with no repating. 1 Answer
Text Mesh Pro UI element goes behind a gameobject? 1 Answer
canvas child of another canvas issue 0 Answers
GameObject.Find always returns null even when the object exists 1 Answer