Announcement

Collapse
No announcement yet.

Performance issues with my inventory/equipment system.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Performance issues with my inventory/equipment system.

    Hey guys, so I ran the profiler tools from session frontend on my game and I detected that my inventory system and item tooltips are very heavy on performance. It makes sense to me because I have lots of visibility and image bindings in UMG for the 36 inventory slots and for the item tooltips. And those bindings all get fired 2-3 times per frame!!!

    My question is, how do you prevent the bindings from running 2-3 times per frame? Or is there a way to code visibility or setting of item icons without using UMG bindings?

    I tried with the stack size text on the inventory slot, and I could program it in beginplay of the inventory slot so the stack size gets hidden for items that can't stack. But the problem is that this only happens on beginplay. And if I then pick up an item, or unequip an item that IS stackable, the stack size text will still be hidden because I did it in beginplay.

    Also, is there a way to detect if a variable or array is changed? If so I can code it to call a custom event or function to set the visibility or icon bindings only when a item gets added to inventory as opposed to doing it 2-3 times per frame with a regular binding.

    Also, I have added the UI_inventory to the main HUD, which is always active. Is there a way to make inventory code only run when the inventory panel is actually opened?

    Thanks in advance!
    Creative Director at Rebel Camp Games

    http://www.rebelcampgames.com
    http://www.forestsofaugusta.com
    http://www.emberheartgame.com

    #2
    Programmers often want something to happen in response to a variable change, and therefore create what is commonly referred to as a Property.

    A Property is simply wrapper functions (Getter and Setter) for your variable.
    These are the steps if you have a float variable called Health.
    • Make the Health variable private (This should hide the Set and Get Health node when accessing it from outside the Blueprint)
    • Create a function called SetHealth
      • add a float input to the variable and have it set the private Health variable
    • Create a function called GetHealth
      • add a float output and return the private Health variable
    Now anywhere where you already set the Health directly you should replace it with the new SetHealth function call.

    If Health is important to many different blueprints you should consider making an Event Dispatcher (OnHealthChanged) and call it every time the Health variable is set. All those other Blueprints (and widgets) can then bind to this event dispatcher and react to this variable.
    Last edited by GarnerP57; 10-17-2019, 03:31 PM.

    Comment


      #3
      Thanks! I will try that!

      Edit: With Event Dispatcher seems to work pretty well! Thanks again!
      Last edited by Rebel Camp Games; 10-17-2019, 02:49 PM.
      Creative Director at Rebel Camp Games

      http://www.rebelcampgames.com
      http://www.forestsofaugusta.com
      http://www.emberheartgame.com

      Comment

      Working...
      X