playMaker

Author Topic: Best-practices question about instantiating prefabs  (Read 2233 times)

ShawnMcCool

  • Playmaker Newbie
  • *
  • Posts: 21
Best-practices question about instantiating prefabs
« on: February 11, 2012, 01:11:00 PM »
I have a character manager FSM.  When a character needs added to a scene an event is sent.  It needs to know which character to add and then I need to set a few variables using script methods.  The problem that I see here is that I need to pass a parameter in some capacity.

So..  This is what I have now.

Global Variable: Character Type (String)

I first set the Character Manager variable "New Character Type".

I send the "Add Character" event to the Character Manager.

This seems clumsy.  What am I missing?

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Best-practices question about instantiating prefabs
« Reply #1 on: February 11, 2012, 05:03:28 PM »
You could use Event Data instead of a global variable. Use Set Event Data to set some parameters, then the character manager FSM could use Get Event Info to get the event data. Seems a little cleaner...

EDIT: Or depending on the number of character types you have, just make an event + state for each one. Then you can also do custom setup on each character type. E.g.. A MakeSoldier state that has a global transition with a MakeSoldier event. Now just send MakeSoldier to the character manager FSM. CharacterFactoryFSM might be a better name...
« Last Edit: February 11, 2012, 05:07:02 PM by Alex Chouls »

ShawnMcCool

  • Playmaker Newbie
  • *
  • Posts: 21
Re: Best-practices question about instantiating prefabs
« Reply #2 on: February 11, 2012, 05:21:00 PM »
The event data solution is definitely better.  The issue is that there are something like 100 character types.  That's a specific need for this design.