I'm having an issue with implementing the Unity OnDestroy() method on the Hololens and I thought I'd ask here to see if anyone has experienced a similar problem. The code I'm looking to run is very simple: Code (CSharp): /// <summary> /// Called when the projectile is destroyed. /// If the target has not been hit, set the score to zero. /// </summary> private void OnDestroy() { if (!hit) this.transform.parent.BroadcastMessage("OnScore", 0F); } As the summary states, this is meant to set the score to zero if the projectile is destroyed without having hit a target. The real mystery for me with this code is that it works entirely as expected within the Unity editor, but for some reason doesn't appropriately affect the score when deployed to the HL. Any suggestions?
Hello, Can you give more information on how you have the project setup? Is the script on the camera or a game object?
Sure thing. This method is part of a ProjectileBehavior.cs script which is attached to a projectile prefab. This prefab is instantiated when the user air taps. ProjectileBehavior.cs contains the private bool hit, which records whether the instantiated object collided with the target GameObject. If you need any additional info I'd be happy to provide it.
Hard to know exactly what is going on Are you getting any errors? Could be the parent object is not receiving the message and your getting a SendMessageOptions.RequireReceiver error.
No error messages on the HL at all. The code runs fine, it simply doesn't set the score to zero when the projectile is destroyed as it does when I run through the editor. I'll check to see if the parent is receiving the message, but it is difficult to debug since I usually rely on the HL code to mimic what I see in the editor. I was hoping that perhaps there were some known issues with Unity code not executing the same when deployed to the device versus being run in the editor.
Can you try running it in the editor with simulation turned on? You can turn this on in the Holographic Emulation window, and use Simulate in editor. This might help narrow down the issue.