playMaker

Author Topic: Broadcast event performance question  (Read 4815 times)

coxy17

  • Beta Group
  • Sr. Member
  • *
  • Posts: 355
Broadcast event performance question
« on: July 13, 2014, 01:37:08 PM »
Hi,

Basically im building a chess game and each square as a trigger, when this happens im using a Broadcast Event to send out an event to loads of FSM's. Would this be ok to use all the time as im not sure if this will impact performance? basically im using it every time the player moves a chess piece.

thanks

Nick

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn
Re: Broadcast event performance question
« Reply #1 on: July 14, 2014, 09:55:24 PM »
How many is "loads" and what is your platform?
It should be fine. I would make a simple stress test scenario on your target platform - not real code, just to test the broadcast performance for what you want to do with it...

coxy17

  • Beta Group
  • Sr. Member
  • *
  • Posts: 355
Re: Broadcast event performance question
« Reply #2 on: July 15, 2014, 03:45:11 AM »
Quote
How many is "loads" and what is your platform?

sorry i meant to say its going to be around 100. I think its not going to be the best option for me. :(

basically i have about 100 triggers and the player is only active in one Trigger at any given time. A seperate FSM sends an event to this trigger, but its the same event for all 100 triggers.

Just had an idea, could i use a SetGameObject and have the 'current active trigger' set itself as the 'GameObjectVariable' and when ready i send the event to this?

or is there a better way? just trying to save on performance.

hope you can help

Nick

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Broadcast event performance question
« Reply #3 on: July 16, 2014, 09:33:41 AM »
Hi,

 Indeed, don't broadcast if you have a way to know to the target, that is definitly better this way. because not only you would send events for nothing ( not too worried about perfs, cause under the hood nothing happens if fsm doesn't implement that event), but what's more problematic is that you woul dneed to check on each fsm that implement that event if it's for itself. So it's best to only send to the desired target, always.

 Bye,

 Jean

coxy17

  • Beta Group
  • Sr. Member
  • *
  • Posts: 355
Re: Broadcast event performance question
« Reply #4 on: July 16, 2014, 10:05:26 AM »
Hi,

Ok. I'll avoid broadcasting. Just out of curiosity, if I create a prefab, will sending the event to a prefab work the same?

Thanks

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Broadcast event performance question
« Reply #5 on: July 16, 2014, 02:32:02 PM »
Hi,

 Yes, if we assume that you have actually created an instance of the prefab, a prefab that sits in the assets is not part of the scene, until it's instantiated ( using "create object"), then it's an GameObject in your scene like any other and will receive global events that it has in its fsm.

 Bye,

 Jean

coxy17

  • Beta Group
  • Sr. Member
  • *
  • Posts: 355
Re: Broadcast event performance question
« Reply #6 on: July 17, 2014, 10:17:25 AM »
Hi,

so you are saying if i made the trigger into a prefab then dragged it back into the scene and replaced, the global variable game object wouldnt work?


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Broadcast event performance question
« Reply #7 on: July 17, 2014, 02:18:35 PM »
Hi,

 It should. what you can not do with prefabs is to store during editing a reference to an object in the scene, you can reference a child of the prefab but that's it, any other external ref must be done either via a global variable or at runtime after the prefab has been instantiated in the scene.

bye,

 Jean

coxy17

  • Beta Group
  • Sr. Member
  • *
  • Posts: 355
Re: Broadcast event performance question
« Reply #8 on: July 17, 2014, 06:41:07 PM »
ok, ive setup the active trigger as a global variable. I use this to target instead of broadcasting. It works great!

I will try and create a prefab from this and see what happens....

but before i do.... my trigger is also targeting another game object FSM ( im specifying this manually by choosing a target). Do i have to change this to target a global variable before creating a prefab? as i guess the prefab will lose the object i specified?
« Last Edit: July 18, 2014, 05:06:57 AM by coxy17 »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Broadcast event performance question
« Reply #9 on: July 18, 2014, 08:11:34 AM »
Hi,

 move away from global variables here. instead have an object "manager" in your scene that has an fsm with a variable referencing that gameobject, and when you instantiate your prefab, either send it an event with a reference of that manager or the gameobject directly.

Bye,

 Jean

coxy17

  • Beta Group
  • Sr. Member
  • *
  • Posts: 355
Re: Broadcast event performance question
« Reply #10 on: July 18, 2014, 02:33:17 PM »
Hi, I understand what you mean, my setup has 100 or so triggers are all the same. They are linked to one prefab.

I have already positioned these in the scene from this prefab by dragging in.

 The issue is regards to instantiate (create object) at runtime, im guessing I would afto remove these from the scene and use this prefab to generate 100 of them back to where I placed them before using coordinates at runtime? Dont think its going to be a quick job :(

sorry if ive got the wrong idea about prefab instantiate. Not sure what to do

« Last Edit: July 18, 2014, 02:36:57 PM by coxy17 »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Broadcast event performance question
« Reply #11 on: July 21, 2014, 08:49:51 AM »
Hi,

 If your prefabs are in a mathematical or logical placement, do that at runtime for sure.

 else, pain :)

 What I would do is create a PlaceHolder maybe? an empty gameobject, that you refer either by name + tag ( for quicker find action), or in ArrayMaker, and then you can go through them at runtime and instantiate whatever at their transform position and rotation, this, coupled with a pool Manager and you are in for a very optimized and flexibile solution.

 Bye,

 Jea

coxy17

  • Beta Group
  • Sr. Member
  • *
  • Posts: 355
Re: Broadcast event performance question
« Reply #12 on: July 22, 2014, 06:19:48 PM »
Hi,

Quote
What I would do is create a PlaceHolder maybe? an empty gameobject


I will look into this...

just curious, I basically i cant use a prefab (unless instantiated at runtime) to talk to a global variable? is that right?

Nick

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Broadcast event performance question
« Reply #13 on: July 23, 2014, 07:46:08 AM »
Hi,

nop, a actual prefab asset just sit there and is not interacting in any form with your scene until your instantiate it, and so it doesn't/can't set or get a global variable like that.

 But I do sense a lot of possible confusion here. So The bst thing for you is to run some tests to verify and experience it for yourselft, this is the best approach for you to remember all this.
 
Bye,

 Jean

coxy17

  • Beta Group
  • Sr. Member
  • *
  • Posts: 355
Re: Broadcast event performance question
« Reply #14 on: July 27, 2014, 07:55:57 AM »
Im not confused too much... I understand the principle of doing it this way now. Just out of curiosity, if i use a EmptyGameObject (Placeholder) as a target, do i need to make this into a prefab first before adding into the scene? or do i just leave them as EmptyGameObjects?

thanks
« Last Edit: July 28, 2014, 08:08:55 AM by coxy17 »