Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Very bad performance with simple macro (no update)

Discussion in 'Visual Scripting' started by Ts1nd, Mar 15, 2021.

  1. Ts1nd

    Ts1nd

    Joined:
    Jan 24, 2021
    Posts:
    108
    My macro has terrible performance when there are 10+ characters on screen.
    The macro works as following:
    1. Get the list of objects with given tag then cache it. Around 10 objects in total
    2. Based on this list set 6 dictionaries with char name + value as following:
    - ThreatDistance dictionary holds info about the distance of the target with given name. Simple use of core function "distance"
    - ThreatDamage dictionary holds info about the damage the char inflicted which decreases by certain amount (once per sec). Also very simple
    - ThreatDPS dictionary which calculates the DPS of the target then compares the DPS to average DPS of all targets and sets number (threat) based on it. Nothing fency.
    - ThreatTargeting dictionary very simply sets value of 25 if being targeted by this char and another +25 if char is being targeted by self. You can calc it in head...
    - ThreatHealth dictionary sets threat based on enemy missing health %. Very simple math.
    - Threat dictionary which is the sum of all above so basically sums 5 values for each of 10 chars so total 50 operations...

    And yet despite triggering this module every second, I get basically 1 second freeze every second because of how intense the calc is! There is no issue with 5 objects but starts to add a lot of lag the more objects there are. I have good gaming PC and I dont expect to have 1 sec lag when 10 objects on screen? I get like 5fps with 5 objects when I put this thing to update instead of once a sec...
    I uploaded the macro if that helps. Note: some functions may be not readable/visible for you as those are another macros.
     

    Attached Files: