playMaker

Author Topic: 1 object, many FSM's  (Read 5802 times)

greg

  • Junior Playmaker
  • **
  • Posts: 68
1 object, many FSM's
« on: February 08, 2013, 05:03:14 AM »
Hey,

Quick question about best practice. I want to structure my code so that each object could have a lot of FSM's handling  each basic feature. This is so i can navigate/iterate when my game starts getting big.

For example, i want the following FSM's on my gun object:
- shot projectile
- muzzle flash
- knockback
- screen shake
- ammo/reloading
- rate of fire
- shell casings

This is so its quick to navigate, and re-useable. Is it alright to do this? Does it have little to no performance hit, to have many FSM's?

Thanks :)

kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: 1 object, many FSM's
« Reply #1 on: February 08, 2013, 07:37:05 AM »
try to use as few fsms as you can get away with. Each FSM will add like 0.05 seconds to your startup time and a lot of empty FSMs can also have a hit on your performance.
Some windows users have also reported their FSM editor performance to be very bad when working with 100+ FSMs .

So if your game will be large (like if it is a 3D Shooter) many FSMs will slow you down in the editor, which may outweigh the development speedup you get from using so many different fsms .
If you don't mind sharing parts of your project with the public I can show you on one of your gameObjects how to create a large yet organized FSM, if you want. A key to this are global transitions imo.
Best,
Sven

greg

  • Junior Playmaker
  • **
  • Posts: 68
Re: 1 object, many FSM's
« Reply #2 on: February 12, 2013, 09:35:51 AM »
Thanks.

Start-up time = the loading time for the game, or how long it takes to preview in-editor?

Empty FSM's? My fsm's have stuff in.. a lot of fsm's will hit the games performance?

Could you give me a few tips for consolidating fsm's without a picture, i guess i just use global transitions to trigger different parts of the fsm like you said.

Kubold

  • Full Member
  • ***
  • Posts: 112
Re: 1 object, many FSM's
« Reply #3 on: February 12, 2013, 10:22:15 AM »
To make it clear:
1. Is it better to have one giant FSM than for example 8 mid-size FSM's on one object?
2. In a singe FSM, Is it better to have 10 nodes with 10 actions in each, done one after another, or 1 node with 100 actions (like: GetPosition in one node and [SetPosition] in second node, or GetPosition, SetPosition in one node)?
« Last Edit: February 12, 2013, 10:26:47 AM by Kubold »

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: 1 object, many FSM's
« Reply #4 on: February 12, 2013, 10:28:40 AM »
Creating an additional FSM and populating it creates another system that it has to run and manage simultaneously. If you can condense those two FSM's into one then the computer only has to process one system.

For instance having an FSM for seamless aiming and another FSM to translate wasd input into transform isn't really possible(maybe, but i havent figured it out) to merge, so you have to have them separate. Whereas having 4 separate FSM's waiting for input from the W, S, A, and D keys would create 4x the amount of work for the computer. Four FSM's would be idling, waiting for input rather than just one, hogging draw calls.
« Last Edit: February 12, 2013, 10:30:12 AM by Lane »
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

Kubold

  • Full Member
  • ***
  • Posts: 112
Re: 1 object, many FSM's
« Reply #5 on: February 12, 2013, 10:49:49 AM »
But isn't a giant FSM also hard to process for the computer?

Let's say I want the object to do a raycast every frame. I would do 2 FSMs - one with a node that is just raycasting, and another FSM with all the walking, running, jumping, crawling etc.
Now - is it better to do it like that, or is it better to add a Raycast Action to literally every node, but have just 1 FSM?

Imagine that there is way more actions to do every frame or half of the time. Instead of ending up with 10 FSM's, but fairly simple, were ending up with 1 FSM, but with a lot of Actions in every node. Is it still better for performance?

Well actually from what you are saying it should, but I want confirmation :)
« Last Edit: February 12, 2013, 10:54:36 AM by Kubold »

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: 1 object, many FSM's
« Reply #6 on: February 12, 2013, 11:29:13 AM »
But isn't a giant FSM also hard to process for the computer?

Let's say I want the object to do a raycast every frame. I would do 2 FSMs - one with a node that is just raycasting, and another FSM with all the walking, running, jumping, crawling etc.
Now - is it better to do it like that, or is it better to add a Raycast Action to literally every node, but have just 1 FSM?

Imagine that there is way more actions to do every frame or half of the time. Instead of ending up with 10 FSM's, but fairly simple, were ending up with 1 FSM, but with a lot of Actions in every node. Is it still better for performance?

Well actually from what you are saying it should, but I want confirmation :)

I guess the performance would be minutely better or the same since its processing the same things but the gameplay would likely get choppy doing it that way since it isn't doing them simultaneously. So you're better off making two FSMs like the first case I mentioned with Aim/Transform. In my mind situations that effect the smoothness of the gameplay are no brainers.

As far as being more efficient i doubt this case would be a big huge saver, stuff that would be repeated on like 50 units or done very often would be most subject to scrutiny.
« Last Edit: February 12, 2013, 11:31:16 AM by Lane »
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: 1 object, many FSM's
« Reply #7 on: February 12, 2013, 02:15:31 PM »
Thanks.

Start-up time = the loading time for the game, or how long it takes to preview in-editor?

Empty FSM's? My fsm's have stuff in.. a lot of fsm's will hit the games performance?

Could you give me a few tips for consolidating fsm's without a picture, i guess i just use global transitions to trigger different parts of the fsm like you said.

Sorry for not replying, I had my hands full at that time.
Start-up time is the time it takes for the editor to compile the game. If you create an empty gameObject and put an empty FSM (well, since I don't know if perhaps PlayMaker makes an exception if it's completely empty, let's say there's a "getOwner" action, in it, which is very cheap and one time only) on it, and then you copy/paste that empty say 100 times, then you should notice a definite increase in start-up time, which is much higher than what actual scrips with the same functionality would add.
But then again, that's understandable. I mean, there's an obvious need for a detailled initialisation before an FSM can be excecuted.

Also, for reasons I'm not sure of (perhaps because of system events and the like) each FSM will also have a continuous impact on your performance, even if it's not actually doing anything. It's not a large impact, but it is probably good to be aware of it.

Apart from global events there's also coloring, which I personally use a lot. By setting certain blocks of states to certain colors (like for me the start state and the init states are always blue) you will find it much easier to work on large FSMs without getting confused .

Oh and btw, this is just a guess, but a common error I see people doing is the usage of global events for global transitions. If your global transitions are only called from within the FSM, then they can also use normal events. If you already do it that way, then great, otherwise you may find that too many global events get difficult to handle ;)
« Last Edit: February 12, 2013, 02:23:58 PM by kiriri »
Best,
Sven