I’ve been chasing my tail for the last few days on this. It seems like a straightforward problem, but I have not found a solution.
I am working on an RTS game and the HUD is supposed to show the available resources on a given planet. The setup is simple. There is an array of icons, an array of enums for each resource type, and an array of floats for the resource amounts. Each icon gets the resource enum value from the planet’s resource array. There is a switch on enum that then assigns the appropriate image to the icon and hides any unused icons. So if a planet only has 1 resource, 2 icons get hidden.
This works fine for the home planet, but other planets appear to grab random images for the icons.
At first I thought it was just grabbing the wrong index or hiding the wrong icons. That’s not the case. In the loop body I specifically check if the number of icons is less than the length of the resource array. So the icons that get hidden are the ones near the end which would have no value if they were bigger than the length.
I considered that the enum switch was not (A) receiving the right value or (B) that the images being set were wrong. That is not the case. I changed the switch on enum to switch on int and converted the value. I also double checked the images being set, however, that step really isn’t needed because the home planet always has the correct icons.
There is only one source that sets the icons. The planets do not have a copy of the icons and do not set themselves. That is only handled by the HUD which checks only the resource types and amounts at each planet and then assigns the image/icon in the HUD.
Not sure, if i fully understand your loop, but generally speaking, wouldn´t it be easier to set/define the resources and their right icons in an extra resource struct?
Then you won´t have to set those icons for every planet, you just have to check, which planet got which resources (an array of resource structs instead of your array of enums) and the amount, and your hHUD would get the correct icon from the resource struct.
Yes, that would be simpler to have them all in one easy basket but it isn’t necessary for the planets to carry around the icons, and that’s an extra struct on top of the current PlanetStats struct that already houses the resources and the amounts. I could add the icons to that, but again, the planets don’t need to carry those around. BUT I did seriously consider that as an option before going down the path that I did.
It turns out that the “Set Member” boxes are not working correctly or I am not using them correctly. I have them set with the Image pin checked for the SlateBrush, however, they’re not updating very well.
To me, it doesn’t make any sense why the “Set Members” boxes are failing. It might be a timing issue. But the old fashioned way works. Has anyone else experienced issues with these things?
I would say, it would make it less error-prone (like the errors you got ^.^), and i doubt, that your planets care, if they got a struct with everything resource related in it, or if it´s spread out over a bunch of separate arrays. Your HUD might care, seems to be easier to just get the correct icon from a struct instead of setting them each time you check a planet.
It’s about memory management. The HUD is the only thing that cares about the icons, so that’s where they should go. If each planet holds a list of all the possible icons when they have no reason to, that’s an unnecessary memory cost, minuscule as it is, but that adds up over time.
I don’t see how it would make it less error-prone. The error that I had, had nothing to do with where the icons are stored. It was caused by malfunctioning Set Members nodes during retrieval.
In either case, if the icons were on the planet’s struct or the HUD’s, they would still need to be retrieved and updated when the player changes location, and the error I had would have still happened.