playMaker

Author Topic: Most effective way to manage 100+ objects?  (Read 1966 times)

frogwise

  • Playmaker Newbie
  • *
  • Posts: 49
Most effective way to manage 100+ objects?
« on: May 12, 2015, 08:06:48 PM »
Hi guys,

Let's say I have these super simple objects that will glow brighter based on how close (distance) the player gets to them. Let's say I plan on having 100+ of these objects per level on mobile. I am not spawning them at runtime - they are placed as part of the level.

What is the most efficient way of creating the FSM's for this behavior? Right now, I have the object as a prefab and on that prefab I have an FSM that checks the distance to the player and changes the glow amount based on that. Now, if I make 100 of these prefabs in the screen, will it become problematic that everyone of them is "listening" for that info and reacting accordingly?

Or is it a better workflow to create a manager that somehow manages all these objects from one FSM?

Again, this is a mobile game, so I am looking for the most cost effective solution to this...

Thanks in advance.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Most effective way to manage 100+ objects?
« Reply #1 on: May 13, 2015, 03:05:09 AM »
Hi,

 100 object is fine. "Listening" to values is not what is costing ( if at all, you could have thousands of listener, it won't affect much). what will affect perf is whazt you do with this value afterward.

typically, what will be costly is to get the real distance ( because there is a square root computation involved) and in your case, this is what could become part of the performance hit. but you should only worry about this if you can witness this either with profiling or with a bad framerate.


Either way, wether you use a manager or an fsm on each, the computation cost will be the same, so you better do this on each object, it will be a lot easier.

Also, I added the "sqrMagnituce" operation to the Vector3 operator Advanced custom action ( get it on the Ecosystem). Please use this operation on all your distance check, this will improve the situation regardless of the context ( since you are not interested in the real value, but only to the relation between each one of them).

Bye,

 Jean

frogwise

  • Playmaker Newbie
  • *
  • Posts: 49
Re: Most effective way to manage 100+ objects?
« Reply #2 on: May 13, 2015, 03:54:52 PM »
Thanks Jean!

I was actually having success using 'Get Distance' before. How will your action differ from that? I'm not sure what you mean by "real distance".

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Most effective way to manage 100+ objects?
« Reply #3 on: May 15, 2015, 08:45:11 AM »
Hi,

 getting the distance between 2 vectors implies a squareRoot, because of the nature of the math equation, and so, if you skip the square root, you can get the distance squared, which is more performant.

the implication from you is a different order of magnitude for the distance values, but  it doesn't matter since you are looking for a relative sorting betwen objects.


only use this new method if you have some performance issue, that's all.

 Bye,

 Jean