How to optimise my simulation ? It starts lagging when I have a 100 actors.

We’re building a simulation with actors that have their own rules (such as moveCloser, moveFurther, reproduce, kill,…). Here’s roughly how it works :

  • We spawn multiples organism (it lags when we spawn more than a 100)
  • The organism can be of 4 different types (cube, cylinder, sphere, cone)
  • We have a rule system where we can add a rule to each type and we can modify its parameters.
  • The rules are actor of the level and each organism call the function “updateMovement” that is implemented by each rule to know where to move. It only calls the function from the rules corresponding to its type
  • Then it moves

Here’s a simplification of what’s inside the blueprint organism (inside the Update Movement, it calls the “GetMovementVector” for each rules) :

Here’s what’s inside the function “GetMovementVector” blueprint moveCloser :

So this means that for each organism, for each rule we need the position of every other organism. Do you think of a way to reduce that ? Do you know if we can replace the for each loop with something else that is faster ?

We did absolutely everything using blueprints, no lines of cpp. We did it that way because we started with a blank blueprint project and we don’t know how to replace some of our blueprint functions with cpp functions. Do you think we could easily replace the “getMovementVector” with a cpp function ?

In general, how could we optimise this type of simulation ? What make things laggy ? When we launch without adding any rules, it still lags, even though there is no logic supposed to happen. This is what I don’t understand, if I just add a 100 actors that don’t do anything at all, no loops, only a random movement it still lags.

1 Like

All of them are calling ‘get actors of class’, which gets all of them…

You need to build a central list of the actors to work with.