playMaker

Author Topic: Array Get Next is too slow!  (Read 797 times)

Silicon Power

  • Full Member
  • ***
  • Posts: 186
Array Get Next is too slow!
« on: May 04, 2021, 06:25:45 AM »
Hey guys, I have an array with 100 items and need to get every item with "Array Get Next" action but it is really slow! why getting an item from an array have to be that slow?

Or maybe it's because of "Create Object" action? because I create a game object after getting an item with Array Get Next?
« Last Edit: May 04, 2021, 06:51:53 AM by Silicon Power »

Broken Stylus

  • Beta Group
  • Hero Member
  • *
  • Posts: 772
Re: Array Get Next is too slow!
« Reply #1 on: May 04, 2021, 08:48:55 AM »
100 items should be very quick to manage, but if you do something in between each "get item", then there lies the issue. Creating an object, just like destroying one, shouldn't be abused.
It's much better to pool objects, creating instances from a prefab at loading.
You should have a step in your application's initialization where you create a pool of instances that you will activate or deactivate at will. It's also much better to use pools for memory management.
If you have a very dynamic system, you'll create your pool full of instances at runtime, during the application's launch, but if you need a few instances, you can create them manually and save them "as is" inside your scene.

The few systems that I know of that are good at managing creation of elements on the fly are Unity's Shuriken system (particles), but outside of this, use tailored pools of instances.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Array Get Next is too slow!
« Reply #2 on: May 07, 2021, 11:45:45 AM »
Hi,

 yep, creating object takes more time depending on the object to instantiate.

 ArryGetNext is lighting fast.  you can try with a simple array of string and log them in the console, you will see it takes a split of a second. you can actually start with an empty array, add 100 items, and then log them all.


Bye,

 Jean