playMaker

Author Topic: Improving performance...?  (Read 4039 times)

Red

  • Hero Member
  • *****
  • Posts: 563
    • View Profile
Improving performance...?
« on: February 12, 2013, 09:37:40 AM »
Yeah, so the game i'm working on is coming along nicely... the weapon systems are what i'm working on today right now but there's something i've noticed and i would like some suggestions as to how to address them.

What i've got is a ninja character that has a shuriken that she throws. the mechanism is set up and the shuriken programming is done but whenever she fires off multiple stars, there is a small performance hit that makes the camera systems motion jerk just a tiny bit (it's the "fully upgraded" version where she throws five stars at once in a nice arc... this is still visible with one star thrown but the effect is pretty much negligible.)

I was looking at the system where we can declare which scripts run in what order and such with the Unity>Edit>Project Settings>Script Execution Order but that seems not to play well with Playmaker's setup since it's technically seeing them as components and the scripts are all separately listed (i tried putting the "move towards" action be in that list since it's technically the action that drives the camera mainly... but no difference was visible.)

so, I come to you, oh PM Wire-uppers (do we have a slang name for ourselves? :P) to see what you would suggest to address this issue. it's mainly with the instantiation of the whole thing and past that it's working well.

Jake

  • Junior Playmaker
  • **
  • Posts: 61
    • View Profile
    • Fluffy Underware
Re: Improving performance...?
« Reply #1 on: February 12, 2013, 12:33:48 PM »
Sounds like you're in need of a pooling manager. Fortunately, you don't need to roll your own... ;D

Jake

julius

  • Playmaker Newbie
  • *
  • Posts: 15
    • View Profile
Re: Improving performance...?
« Reply #2 on: February 12, 2013, 12:37:40 PM »
Whats the basic setup your using to put the shuriken on the screen? Are you using the create object action or using a pool manager? What is driving the camera?

If your not using a pool manager already then Jake is right SmartPool works well if you don't want to make your own. You can make a sudo one using playmaker to activate and deactive an array of gameobjects as well.


[Hehe yep kiriri]
« Last Edit: February 12, 2013, 12:43:26 PM by julius »

kiriri

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
Re: Improving performance...?
« Reply #3 on: February 12, 2013, 12:37:59 PM »
Pooling you must, my wireman...

No, seriously, I might be wrong, but  if you actually create thos 5 shurikens at runtime then that may be what's causing the lag. Unity is very weak at instantiating gameObjects at runtime, so your best bet is to create like 100 shurikens in the editor, parent them to a gameObject in the scene, making them inactive and then using getChild coupled with activateGameObject each time you want to spawn a new shuriken. Then once that shuriken hits, it just parents itself back to the original gameObject and deactivates itself.

This way you never create any new shurikens, you just always reuse your 100. (or proobably less in your game) . Deactivated gameOBjects are virtually free.

Did that help?

[Edit: That's creepy, 3 ppl decide to answer at the same time :D]
Best,
Sven

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14493
  • Official Playmaker Support
    • View Profile
Re: Improving performance...?
« Reply #4 on: February 12, 2013, 01:07:16 PM »
Hi,

 Yes, pretty amazing community I must say!

bye,

 Jean

Red

  • Hero Member
  • *****
  • Posts: 563
    • View Profile
Re: Improving performance...?
« Reply #5 on: February 13, 2013, 07:36:07 AM »
Wow! Thanks for the great replies.

i'll look into that pooling manager but since right now my finances are tighter, i'll have to work on one here. (i think it's going to be best to create a "universal" one rather than one for each weapon system given the way that the game i have is set up.)

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2488
  • Yup.
    • View Profile
    • Cleverous
Re: Improving performance...?
« Reply #6 on: February 13, 2013, 09:13:58 AM »
If I understand pooling correctly you're basically just trying to stash an object somewhere so you can avoid using create object. I'm guessing you'll build all of the projecticles and spawnables into the scene at run time and just 'move' or 'activate' them instead of creating them, right?

kiriri

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
Re: Improving performance...?
« Reply #7 on: February 13, 2013, 09:45:38 AM »
yep, have a look at my previous post, if that didn't make it clear I could create an example if you want.

Plugins like poolmanager create the gameObjects after you press play, but before the game actually starts. And since it's effectively nothing more than activating and deactivating the gameObjects, you can do it yourself if you're broke ;)
I personally use Poolmanager which makes the project look a bit more organized imo. I think it also tries to reset gameObjects on respawn, something which with PlayMaker you have to do manually in what I call an "init" state which should be your start state. Though in the example of shurikens, there may just be nothing that needs resetting, dunno.
Best,
Sven

Red

  • Hero Member
  • *****
  • Posts: 563
    • View Profile
Re: Improving performance...?
« Reply #8 on: February 13, 2013, 11:26:37 AM »
Lane: Yep, it's the same as what Kiriri said.

Though, without pool-manager it is possible to do it surprisingly easy with Playmaker but you kinda do have to set up a "enable/disable" system that controls the things such as the velocity, any particle effects, etc... with the shurikens, since they have a trail-renderer applied, i had to figure out how to adjust it and the proper timing (hint: next frame event is your lucky star in this to ensure that the events are firing off in the proper order)

it's also just as simple to tell it to spawn the appropriate number of items you want to store and if you use the parenting actions and the enable/disable system i mentioned, you don't have to worry about them flying around and mucking up things in your scene (though if you have them able to use a rigid-body on other instantiations of themselves, you might want to consider enclosing them in a box so that if they do fly around from the rigidbody interacting with others like themselves and their position is stored in the same space, that might help to keep them in one space... but, for what i used, i just told the physics engine to give them a separate layer (all projectiles) and ignore other projectiles. it's unlikely that you'd have players firing bullets and hitting other bullets anyway.)

DoraHarris

  • Playmaker Newbie
  • *
  • Posts: 2
    • View Profile
Re: Improving performance...?
« Reply #9 on: March 03, 2013, 11:58:03 PM »
Some objects are locked and can't be reused. I reported this issue to developer and he ensured that it will be fixed soon.

Red

  • Hero Member
  • *****
  • Posts: 563
    • View Profile
Re: Improving performance...?
« Reply #10 on: March 05, 2013, 12:29:54 PM »
Oh, And one thing i was pointed towards... With a pooling system, you can set it to be dynamic very easily with Playmaker.

the process that he suggested was to have an initial spawning amount (if you have it spawn the objects at run-time) and with the "child count" action, you can keep tabs and then tell the pool to spawn more if your child cound falls below a certain level. I'm going to see about putting that into practice since at the start of each scene (with the ninja as an example) it spawns 50 shuriken... This is all well and good but it still gives a noticeable lag at the start of the level (though i am planning on a sort of "intro" sequence to each level anyway because there are some FSMs that do need a bit of wait-time to ensure that everything threads together properly) so, if i, say, tell it to spawn 10... then if the child count falls below 5 (since the ninja won't be throwing more than 5 at a time depending on how they have that particular power slotted) it'll spawn more... at the end of the level it does mean that there is a potential for there to be hundreds (though, i am basically adding in a cooldown system to each weapon so as to prevent players spamming a power so that is not a very likely thing to happen afaik)

I'll see if i can put together something so that people can figure it out. I know i'm behind on the video tutorials but i do have an excuse (though it is only that, an excuse) in that my second monitor kinda bit the bucket... and i do like to have all the notes and lesson plans/infographics/etc on the second screen... still, that is still merely an excuse at this point and i shouldn't just sit back and let myself accept that because, well, it IS only an excuse.)

kiriri

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
Re: Improving performance...?
« Reply #11 on: March 05, 2013, 12:40:22 PM »
Hey,
since you're probably using the same kind of shurikens in each and every level you can fix the lags on level load by marking your empty which stores all the shurikens as "Don't Destroy On Load". Then if you save the empty in a global variable (via get Owner as soon as the empty is loaded for the first time) you can then use that global variable in every scene. That way you could create your 100 shurikens while the game starts and then cover the lags with a loading screen. After that you would never have to create them again, because your empty will no longer be destroyed when you load a new scene/level.
Best,
Sven

Red

  • Hero Member
  • *****
  • Posts: 563
    • View Profile
Re: Improving performance...?
« Reply #12 on: March 05, 2013, 07:31:33 PM »
Hey,
since you're probably using the same kind of shurikens in each and every level you can fix the lags on level load by marking your empty which stores all the shurikens as "Don't Destroy On Load". Then if you save the empty in a global variable (via get Owner as soon as the empty is loaded for the first time) you can then use that global variable in every scene. That way you could create your 100 shurikens while the game starts and then cover the lags with a loading screen. After that you would never have to create them again, because your empty will no longer be destroyed when you load a new scene/level.

You know, that thought hadn't even occurred to me!

Wow! learn something new every day! Thank you!