playMaker

Author Topic: Actions that Use GetComponent  (Read 1300 times)

Rebooter

  • Playmaker Newbie
  • *
  • Posts: 21
Actions that Use GetComponent
« on: October 27, 2019, 05:34:25 PM »
Does it affect performance a lot in actions that call GetComponent from OnEnter? I'm thinking for example of NPCs that have lots of states with PathFinding actions, so you might start getting a lot of GetComponent calls if you have many NPCs at once. I made a few custom actions that work with NavMesh agents and I added an optional NavMeshAgent object field for specifying the agent object directly. Is it worthwhile to do this?

Broken Stylus

  • Beta Group
  • Hero Member
  • *
  • Posts: 772
Re: Actions that Use GetComponent
« Reply #1 on: October 28, 2019, 07:41:16 AM »
It is true that those Get/Set actions should be reduced to a minimum and you should prioritize the use of dedicated actions, but that means coding them.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Actions that Use GetComponent
« Reply #2 on: October 29, 2019, 02:42:48 AM »
Hi,

 yes, Broken Stylus is right. Cache all your components when possible by querying them at the start state, saving them into a fsmobject variable.

It's especially important in your game loop, for menu items and singular calls, you are fine though.

Bye,

 Jean