playMaker

Author Topic: Custom events?  (Read 6768 times)

Krileon

  • Full Member
  • ***
  • Posts: 107
Custom events?
« on: January 27, 2013, 01:32:33 PM »
I'm trying to write a custom event that works exactly the same as Trigger Event for PoolManagers Spawn and Despawn. The API documents are as follows.

http://docs.poolmanager.path-o-logical.com/code-reference/events

How do I go about making my own custom FSM variable like TriggerType? I'm having a hard time finding any information about this as it's all contained in the DLL. Please provide full documentation of classes and functions at some point so this can be further extended easier.

I need to also know how to extend Fsm.HandleTriggerEnter to do for example Fsm.HandleSpawn and Fsm.HandleDespawn.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15496
  • Official Playmaker Support
Re: Custom events?
« Reply #1 on: January 28, 2013, 01:01:56 AM »
Hi,

 Have you checked my implementation of Pool Manager? this is I think the best way for you to see one possible way to do what you want to do.

 basically the key is to write a middle man, in the shape or a prefab likely, or a singleton at least, that bridge any kind of framework with playmaker.

https://hutonggames.fogbugz.com/default.asp?W839

there is also the photon bridge I created, this one is really going deep into integrating with PUN, so this is also a very good example to study.

https://hutonggames.fogbugz.com/default.asp?W928

Yes, playmaker API is lacking documentation unfortunatly, hopefully this will be addressed soon.


If that doesn't answer your questions, let met know, and I'll go more into details. It is planned that I update my bridges to pool Manager and TargetPro someday, this could be the right opportunity.

bye,

 Jean

Krileon

  • Full Member
  • ***
  • Posts: 107
Re: Custom events?
« Reply #2 on: January 28, 2013, 01:04:45 PM »
Yes, I've reviewed your implementation. I wrote my own using PoolManager4 and I've also implemented more usages then yours. Nor does yours implement the OnSpawn or OnDespawn events (I am not talking about the functions, I've those implemented and working fine).

I'm not talking about API usages and such. I've all that done already. I'm talking about new Events such as those utilized by "Trigger Event" or "Collision Event". In order to add more I need to know how to extend PlayMaker with handlers for them and to add my own dropdown usage to select the trigger.

I don't want to have to create an object to bridge the two. PlayMaker simply needs to allow me to extend it with event handlers in the same way I can easily extend with new actions, but that's impossible to review or implement as it's all contained in the DLL (I stress my frustration with dang DLLs here; willing to pay 3x the price for some source...).

Will review your Photon implementation.

Krileon

  • Full Member
  • ***
  • Posts: 107
Re: Custom events?
« Reply #3 on: January 30, 2013, 03:48:29 PM »
Took a look at your Photon implementation and don't quite understand what's going on. Hopefully documentation or a tutorial can be made available to explain how to add custom events. I'd like to avoid having to use a gameObject as it appears you're doing as I don't understand why that's needed (script is already on a game object..).

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15496
  • Official Playmaker Support
Re: Custom events?
« Reply #4 on: January 31, 2013, 12:46:27 AM »
Hi,

 ok, basically you need a playmaker fsm somehow to create that global event ( you create an event and you mark it global).

now, for that event to survive projects, load on other scenes etc etc, it needs to be on gameObject in your scene ( it could be sufficient to have it in a prefab, but that's dangerous I feel).

 That's one of the reason why I have a prefab for Photon, it holds all the logic AS WELL as the global events I have created for this bridge.

Now. in order to fire these trigger, I simply do it via script, that's the second reason why I need a gameObject as prefab on my scene to act as a broker between photon and playmaker. I also have one of this bridge on each photonview enabled gameObject, because they ought to receive custom events too.


I think you are overthinking this. Creating a custom global event is very easy, there is no real difficulty here.

to summarize:

In my prefab "PlayMaker Photon Proxy" I have a fsm: "Photon messages interface"

If you open it, there is no logic implementation at all, it's  sole purpose is to keep the declaration of the global events needed. Go to the Events tab, there are all there. That's where I created them originally. If one day I need another event because photon evolved, that's where I will add a new event and check it as global.

If you open the script PlayMakerPhotonProxy ( attached to this prefab), you can see how I then trigger them events.for example in the method Update_connectionStateWatcher I simply broadcast events.

if you want a more complex implementation, have a look at the script PlayMakerPhotonGameObjectProxy.cs

I fire events ONLY to that gameObject and it requires a bit more use of the playmaker api: sendPhotonInstantiationFsmEvent:

Does that help you understand more about how to do custom events? If no, maybe you can describe what you are after?

bye,

 Jean


ps: yes, it could be possible to request PlayMaker to implement some kind of script based event declaration to avoid such fsm proxies, but I don't see anything wrong with this to begin with.

Krileon

  • Full Member
  • ***
  • Posts: 107
Re: Custom events?
« Reply #5 on: January 31, 2013, 08:18:03 AM »
I see, that clears up a few things. What if I don't need/want a global event? Can I avoid the need of a gameObject? For example can I just put the "OnSpawned" function inside of the custom action script then inside of that function fire a FSM event? This way to use the event you need to add an action then select an event from the dropdown for it to fire. I just don't want to have to create a gameObject proxy to pass events to PlayMaker, IMO it shouldn't have to work this way and sounds like a hacky workaround to me.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15496
  • Official Playmaker Support
Re: Custom events?
« Reply #6 on: February 02, 2013, 03:53:08 PM »
Hi,

Yes you can fire a random event, it will just fail if that event is not implemented. so in the end you will have to create that event in the fsm that wants to receive it. you use the same api call, and put any string you want, if that string is an event that is on the gameObject fsm and implemented as a transition or global transition, it will be fired. I never do that tho, It's "better" ( as, I personnaly think it is... it's only my opinion here, not a statement :) ) to properly declare custom events, especially if they are global. I actually do that on one framework I created last year, where you would define gui elements via xml, so of course, events would have to be totally left to the developer to decide and implement, I could not do otherwise, and it works very, very well actually. If you are interested to see the source, pm me, I'll happily share it with you, it has a ton of crazy features, both xml and playmaker wise. It's uber powerful :) only never had the time and energy to finish it, it's a too big project for my spare time.

bye,

 Jean

phannDOTde

  • Full Member
  • ***
  • Posts: 238
    • Peter Hann .de
Re: Custom events?
« Reply #7 on: January 10, 2014, 04:49:58 AM »
Hey Jean,

Is there any Update on that Pool Manager Bridge you mentioned in this Post? I got the same Problem that without the Option to performe inits on a Global "OnSpawned" Event from Pool Manager within my FSM the implementation becomes kinda worthless. There seems to be no good Way to reset the FSM attached to the pooled Objects. ("OnDeSpawn" might be usefull aswell). Couldnt they be listed as "System Events" as soon that I add Pool Manager to my Project? I'm no coder so I'm unable to do that Bridge on my own :-/

Would love to get some reply on that matter. Thanks

greets
Peter

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15496
  • Official Playmaker Support
Re: Custom events?
« Reply #8 on: January 10, 2014, 06:03:16 AM »
Hi,

 The best way is to use "reset on Disable" option for the fsm on the prefab used in your pools, and then you can reset them by disabling them. If you must do this, I would even consider having a Fsm acting as a manager to disable enable fsm and components on that prefab based on wether it is live or waiting in the pool.

 It's not possible to define global events as "System" events, but that's only a cosmetic labeling, they all performs exactly in the same way within a Fsm logic.

I am not sure where is your struggle to use PlayMaker and Pool Manager Here, if you have a use case, let me know, and I'll double check on how to tackle that.


 Bye,

 Jean

phannDOTde

  • Full Member
  • ***
  • Posts: 238
    • Peter Hann .de
Re: Custom events?
« Reply #9 on: January 10, 2014, 05:49:57 PM »
Hi Jean
Thanks for your quik reply. An Manager isnt the best solution for me since many Objects could send "despawn" Events at the same time - I fear that there would be overlaps resulting in lost or delayed event reactions. So what I tryied now is that I reset the new spawned Object (from the Pool) with an Activate Toggle. Even if I deactivate/Activate the Objects right after they been spawned they still behave in strange ways. It seems that I cant make sure that all FSM on the Objects are set back to the Start State. And on the other hand it feels like a "Hack solution" going throug the hole Project adding Deactivate/Activate Actionsequenzes to every Spawning Action.

I.E. I got an Self Aiming Projectile FSM. As soon I loop the Action it works every time a shot is fired. As soon as I got an non looping behaviour at some point the Spawned Shots dont behave like the should since Init-State arent called.

I saw your Post here: http://hutonggames.com/playmakerforum/index.php?topic=4266.msg20050#msg20050

But I'm just not code wise bright enuff to work with that.

The best thing what for me looks consistent to PoolManagers Concept would be to have some way to directly get/use the OnSpawn and OnDeSpawn Events.

Not sure what the trade off would be to support the PoolManager Events and add something to the Actions Package since I'm not the first one looking for this and this Post allready had a lot of attention. But anyway another way around would be to have some radio button on the "Pmt Spawn Action" to reset all FSM to initial state at Spawn. Would do the Trick here to make sure every FSM Starts right  with its init state.

Take a look at the attached Screenshots if something is unclear.

greets
Peter

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15496
  • Official Playmaker Support
Re: Custom events?
« Reply #10 on: January 14, 2014, 07:06:52 AM »
Hi,

based on the other thread, It's sorted isn't it?

Bye,

 Jean

phannDOTde

  • Full Member
  • ***
  • Posts: 238
    • Peter Hann .de
Re: Custom events?
« Reply #11 on: January 14, 2014, 09:24:30 AM »

Hey Jean,
yea for now it is :-)

greets
Peter