playMaker

Author Topic: Enabling Behaviors  (Read 8010 times)

artician

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 318
Enabling Behaviors
« on: December 18, 2011, 05:20:35 PM »
I was trying to use the Enable Behavior to alternate between a Collider and a Character Controller on an object.  I'm using this action to activate/deactivate a lot of things, but for these two in question, it simply doesn't seem to work.  Playmaker reports that it can find neither component on the object.  I would love to know if it isn't possible to use this Action to modify physics objects!

Thanks as always!


artician

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 318
Re: Enabling Behaviors
« Reply #1 on: December 18, 2011, 11:01:06 PM »
Some additions to the issue.

I was looking for a workaround for the above issue (which would still be a preferable method if anyone can tell me how to do it properly).

Instead of using Enable Behavior Actions, I instead began Destroying and Adding the components I required.  I have an Enter State, InAction State, and Exit State.  Each does this:

Enter State -
Destroy Component > CharacterController
Destroy Component > CharacterMotor
Destroy Component > PlatformInputController
Add Component > New Collider
Add Component > My Alternate Control Script

InAction State -
Just monitors properties and changes animation on the skinned mesh object, then detects when it's time to switch back.  This state likely has nothing that's contributing to the issue I'm encountering.

Exit State -
Destroy Component > New Collider
Destroy Component > My Alternate Control Script
Add Component > CharacterController
Add Component > CharacterMotor
Add Component > PlatformInputController
Action > ControllerSettings
Action > CharacterMotor Settings
Action > PlatformInputController Settings
Finish

The last action in this list state uses the ControllerSettings Action that Alex uploaded 6 months ago.

The problem I'm encountering is that the CharacterController, CharacterMotor and PlatformInput Settings Actions don't work more than one time.  If I switch the character to alternate controls and back, the exit state correctly adds a new CharacterController (and other components), and configures the CharacterController, CharacterMotor and PlatformInputController properly. 

If I activate the switch between controls a second time, the Exit script correctly creates the CharacterController, but doesn't configure the settings properly. 

To test this, I created a second state after the Exit State that only configured the settings of the new CharacterController and it's associated components (so now these components were being configured twice after creation), however the error still persists after a second switch between these states.

So, in addition to the issue I posted about above, I have stumbled into some limitation to configuring these components in general.  I definitely need some help on this, since now my workarounds aren't working around the problem.  :)

Any replies are appreciated.  Many thanks.



jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Enabling Behaviors
« Reply #2 on: December 19, 2011, 05:09:41 AM »
Hi,

 Have you tried prefab? I know it's limited with playmaker, but I do create objects ( not character controllers tho) using prefab and complex playmaker stuff in it that communicate back and forth with global managers and stuff and that works fine creating and destroying them.

 If not, could you share a project sample showing your problem?

Bye,

 Jean

artician

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 318
Re: Enabling Behaviors
« Reply #3 on: December 19, 2011, 02:48:16 PM »
Actually, the reason I went down this path was because I hit trouble using the prefab method, but at this point I think it might be best to go back and explore more alternatives to it.

I was just hoping, for the sake of cleanliness, that I could put all player-mechanics onto one player game object.  Hopefully Alex will be able to shed some light on the Character Controller issue and maybe show us there are some limitations to the component we weren't previously aware of.

If all else fails, yes I will provide an example, because that will be the only choice I might have left.  :)

Thanks for your reply Jean!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Enabling Behaviors
« Reply #4 on: December 20, 2011, 01:06:44 AM »
Hi,

 Yes, have a go again at prefabs.

 what problem do you havce exactly with them.

 Remember, you can set variable and send event to a gameObjec or prefab without even knowing it will respond, it's perfect with prefab. Get the prefab in a fsm variable, and then you can send event to it or query for some fsm just by referencing fsm with a string. If your object has indeed that fsm it will respond just fine.

 the thing you can't do if I recall well is to store references of other gameObjects outside the prefab. No such big deal, simple us "find GameObject" at some point within the prefab, either after an event is fired or when the prefab starts.

Bye,

 Jean
« Last Edit: December 22, 2011, 06:51:50 AM by jeanfabre »

artician

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 318
Re: Enabling Behaviors
« Reply #5 on: December 22, 2011, 05:39:20 AM »
The issue I was having before, and seem to be still having, is that I would deactivate my player object, and instantiate my Alternate-player object, but the editor would crash to desktop with no report, every time. 

I've deactivated my player object in other parts of the script without this issue before, so I don't know why this is an issue this time.  It's also worth mentioning that I can destroy the player object before instantiating the alternate-player, and that works fine!  The only reason I was reluctant to use this latter method is because I don't want to be pulling my player object in and out of memory every time you switch control modes.  If I destroy it and reinstantiate it, doesn't that cause the mesh, skeleton, animations and scripts to repeatedly load and unload?  This wasn't clean enough for me, but it seems to be my only choice at the moment. 

Thanks again for your advice.  I welcome any more you have to offer!  :)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Enabling Behaviors
« Reply #6 on: December 22, 2011, 06:58:54 AM »
Crashes...

Something odd is happening indeed. are you saying that the crash did not happen on other part of the script meaning not with playmaker, and that if you try with playmaker it crashes?

I think you should look into "pausing" instead of enabling/disabling. if you are confortable enought with scripting, implement a function on all the required script that pause the behavior, you don't destroy or disable any script, you simply pause them by basically not doing anything, not responding to user inputs etc etc. Then you avoid all sorts of problems indeed, no re enabling routine that can cause current state to be lost, not mesh regeneration or anything like that. SO you can have two system happily leaving one next to each other, only one of them is always paused and doing nothing.

 Does that make sense?

If you do have playmaker actions involved in these two modes, simply implement a pause by going to another state and upon "unpause" go back to the required state for the system to be active again. HEre again, I don't suspect any crash or weird results.

Bye,

 Jean

artician

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 318
Re: Enabling Behaviors
« Reply #7 on: December 22, 2011, 03:52:59 PM »
yeah I've definitely created an error on my own, but I haven't been able to track it down.  It's usually my fault, but I'm still curious about the character controller component creation issue, because that's certainly a bug of some sort.

I don't think I can "pause" my player, here is why:
I need to completely replace the Player Object with the Alternate-Player Object.  Both have their own physics (PO has a character controller, and APO has a sphere collider), and they both need to occupy the same space.  I guess I could "pause" the PO and then move it out of the way, instantiate the APO in it's old location, and then swap them again and "unpause" the PO when I'm done...?

Thanks for helping me think this through! 

Happy Holidays.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Enabling Behaviors
« Reply #8 on: December 23, 2011, 12:55:25 AM »
Hi,

 Don't want to give you wrong advices here, but Have you tried to simply turn the mesh rendering off ( and any colliders for example? then no arm, you don't see PO but it's there without too much trouble to manage.

 Else, sometimes with 3d ( I don't know your level here, so please forgive me if the advice is dumb... :) we tend to forget we don't have to apply natural rules normally applying to our physical world. creating, deleting and recreating meshes on the fly is something the 3d engine can do very well in your case. You are not like creating thousands of meshes at a time, just one. So I would not be afraid to just destroy and recreate on a per needed basis if that makes your life easier. Else you can have fun with layer mask and have the camera ignoring either PO or APO during rendering: that would be also something to consider maybe.


Bye,

 Jean