playMaker

Author Topic: [SOLVED] NullReferenceException DestroyImmediate  (Read 4754 times)

amaranth

  • Full Member
  • ***
  • Posts: 172
[SOLVED] NullReferenceException DestroyImmediate
« on: April 16, 2012, 01:28:07 AM »
I think this might be a bug that I've found. I updated to 1.3.2 yesterday.

1. I create FSM
2. Add State 1
3. Add State 2
4. In State 1, I add a Trigger Event and link the state to State 2.
5. In State 2, I add a Create Object Event.
6. When I run the game, I get the error below.
7. If I move Create Object to State 1 and put it after Trigger Event, everything runs fine.
8. I closed Unity and reopened. Same issue persisted.

Code: [Select]
Destroying object immediately is not permitted during physics trigger and contact callbacks. You must use Destroy instead.
UnityEngine.Object:DestroyImmediate(Object, Boolean)
SmoothMoves.BoneAnimation:CreateComponents()
SmoothMoves.BoneAnimation:CreateAnimation()
SmoothMoves.BoneAnimation:Awake()
UnityEngine.Object:Instantiate(Object, Vector3, Quaternion)
HutongGames.PlayMaker.Actions.CreateObject:OnEnter() (at Assets/PlayMaker/Actions/2-PlayMaker Scripts/CreateObject.cs:82)
HutongGames.PlayMaker.FsmState:OnEnter()
HutongGames.PlayMaker.Fsm:EnterState(FsmState)
HutongGames.PlayMaker.Fsm:SwitchState(FsmState)
HutongGames.PlayMaker.Fsm:DoTransition(FsmTransition, Boolean)
HutongGames.PlayMaker.Fsm:ChangeState(FsmEvent)
HutongGames.PlayMaker.Fsm:Event(FsmEventTarget, FsmEvent)
HutongGames.PlayMaker.Fsm:Event(FsmEvent)
HutongGames.PlayMaker.Actions.StringCompare:DoStringCompare() (at Assets/PlayMaker/Actions/2-PlayMaker Scripts/StringCompare.cs:61)
HutongGames.PlayMaker.Actions.StringCompare:OnEnter() (at Assets/PlayMaker/Actions/2-PlayMaker Scripts/StringCompare.cs:35)
HutongGames.PlayMaker.FsmState:OnEnter()
HutongGames.PlayMaker.Fsm:EnterState(FsmState)
HutongGames.PlayMaker.Fsm:SwitchState(FsmState)
HutongGames.PlayMaker.Fsm:DoTransition(FsmTransition, Boolean)
HutongGames.PlayMaker.Fsm:ChangeState(FsmEvent)
HutongGames.PlayMaker.Fsm:Event(FsmEventTarget, FsmEvent)
HutongGames.PlayMaker.Fsm:Event(FsmEvent)
HutongGames.PlayMaker.Actions.TriggerEvent:DoTriggerEnter(Collider) (at Assets/PlayMaker/Actions/2-PlayMaker Scripts/TriggerEvent.cs:38)
HutongGames.PlayMaker.Fsm:OnTriggerEnter(Collider)
PlayMakerFSM:OnTriggerEnter(Collider)

Note: What's strange to me is that DestroyImmediate was called even though I requested to create a new object.
« Last Edit: May 02, 2012, 08:25:34 PM by Alex Chouls »

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: NullReferenceException DestroyImmediate
« Reply #1 on: April 18, 2012, 03:54:06 PM »
From the log, it looks like the bug is in SmoothMoves:
SmoothMoves.BoneAnimation:CreateComponents()

This is the key info:
Destroying object immediately is not permitted during physics trigger and contact callbacks. You must use Destroy instead.

You'd probably get this error with a script too, so I'd post this on the SmoothMoves forum, or contact the author.

A possible workaround for now, is to delay the CreateObject action, e.g., Use Next Frame Event to transition to a separate CreateObject state in the next update. This should avoid the error, but might introduce a one frame delay (off hand I can't recall if physics callbacks are handled before or after Update in Unity).

amaranth

  • Full Member
  • ***
  • Posts: 172
Re: NullReferenceException DestroyImmediate
« Reply #2 on: April 18, 2012, 05:33:23 PM »
Sending him this info now. :)

Yup, that's what I did. I added a .01 wait and it fixed the problem.
« Last Edit: April 18, 2012, 05:39:39 PM by amaranth »