I’m noticing a 102ms performance hit when my player encounters an object in the world - this causes a visible/obvious lag in the game, but only on my PC (in the editor). When I play test this on my phone (Pixel XL), there isn’t an apparent frame hit
The reason for the lag is because when the player encounters an object, I load that objects “icon” from Resources and add it to the inventory screen - but I do so by raycasting to all inventory slots in a list until the raycast finds an open place to put the icon. This is a larger than normal icon, so there are 4 raycast targets per “space check”
I’m wondering why I notice this lag on my PC, but not on my phone?
Any alternative ideas for adding multi-sized objects to inventory also welcome : |
When you say “raycast” - you mean iterating over the list that represents your player inventory in your game (and if you find a free slot you check the neighbouring slots?)* Even if there is a few thousand slots that’d well under a millisecond.
Could the issue be actually loading the resource from disk, perhaps your phone is loading a compressed texture (already in a format ready for the GPU) from an SSD (no seek time) and your PC is loading say a PNG from a mechanical harddisk (seek time, then decompress the PNG, perhaps build mip mips and stuff…) and the reason this kills your frame rate is you aren’t say doing it asynchronously?
*I ask because I can’t understand how raycasting applies to an inventory system
Sounds like a totally viable explination as to why there was a difference in framerates - I’ve since found a way to replace raycasting and achieve the same result, but thanks for your feedback, it’s a ueful theory
All of the UI slots were essentially 10x10 sprites positioned in a grid within the inventory canvas - each slot had a collider, and when an object was collected I added an icon to one of these slots and deemed it “occupied” - I was raycasting to these slots to see if they were “occupied” or not, but as mentioned above found a much more efficient way to do this. thanks again!