playMaker

Author Topic: OnFixedUpdate, OnCollisionEnter, OnCollisionStay... not called? [SOLVED]  (Read 4745 times)

GarthSmith

  • Playmaker Newbie
  • *
  • Posts: 31
  • Games. Math. Code.
    • Garth Smith's Website
Hello Playmaker Forum!

I'm trying to figure out why this action doesn't seem to ever call OnFixedUpdate, OnCollisionEnter, OnCollisionStay, or OnCollisionExit.

Anyone think of ideas why these functions aren't getting called? Why is only the first Debug in OnEnter getting displayed?

Code: [Select]
using UnityEngine;
using HutongGames.PlayMaker;
using TooltipAttribute = HutongGames.PlayMaker.TooltipAttribute;

public class MyCustomAction : FsmStateAction {

public override void OnEnter () {
                // This displays. None of the other debugs display.
Debug.Log ("{" + Time.realtimeSinceStartup + "} MyCustomAction is running OnEnter()");
this.Fsm.HandleFixedUpdate = true;
this.Fsm.HandleCollisionEnter = true;
this.Fsm.HandleCollisionStay = true;
this.Fsm.HandleCollisionExit = true;
}

public override void OnFixedUpdate() {
Debug.Log ("{" + Time.realtimeSinceStartup + "} OnFixedUpdate() running.");
}

void OnCollisionEnter(Collision collisionInfo) {
Debug.Log ("{" + Time.realtimeSinceStartup + "} Collision Enter!");
}

void OnCollisionStay(Collision collisionInfo) {
Debug.Log ("{" + Time.realtimeSinceStartup + "} Collision Stay!");
}

void OnCollisionExit(Collision collisionInfo) {
Debug.Log ("{" + Time.realtimeSinceStartup + "} Collision Exit!");
}
}
« Last Edit: June 23, 2014, 08:14:53 PM by Alex Chouls »

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4002
  • Official Playmaker Support
    • LinkedIn
Take a look at the built in physics actions and checkout the Awake method.

For example, in Trigger Event:
Code: [Select]
public override void Awake()
{
switch (trigger)
{
case TriggerType.OnTriggerEnter:
Fsm.HandleTriggerEnter = true;
break;
case TriggerType.OnTriggerStay:
Fsm.HandleTriggerStay = true;
break;
case TriggerType.OnTriggerExit:
Fsm.HandleTriggerExit = true;
break;
}
}

This is a performance optimization to only add physics event handlers if the FSM needs them.

GarthSmith

  • Playmaker Newbie
  • *
  • Posts: 31
  • Games. Math. Code.
    • Garth Smith's Website
Thanks for the example!

Putting those lines in Awake() worked, but they didn't work in OnEnter(). Good to know.

I don't know how much time you guys have to update documentation, but this web page suggests using OnCollisionEnter, OnCollisionStay, OnCollisionExit, but I found from your example that these should be DoCollisionEnter, DoCollisionStay, DoCollisionExit.
https://hutonggames.fogbugz.com/default.asp?W350

I got everything working now as I intend! Thanks for your help and the quick reply!

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4002
  • Official Playmaker Support
    • LinkedIn
Glad you got it working, and thanks for the bug about the docs. I updated the doc so hopefully it's a little clearer...