Search Unity

OnDestroy() issue on Hololens

Discussion in 'VR' started by Chance_Fate, Feb 27, 2017.

  1. Chance_Fate

    Chance_Fate

    Joined:
    Feb 27, 2017
    Posts:
    3
    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):
    1. /// <summary>
    2. /// Called when the projectile is destroyed.
    3. /// If the target has not been hit, set the score to zero.
    4. /// </summary>
    5. private void OnDestroy()
    6. {
    7.    if (!hit)
    8.        this.transform.parent.BroadcastMessage("OnScore", 0F);
    9. }
    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?
     
  2. Unity_Wesley

    Unity_Wesley

    Unity Technologies

    Joined:
    Sep 17, 2015
    Posts:
    558
    Hello,

    Can you give more information on how you have the project setup? Is the script on the camera or a game object?
     
  3. Chance_Fate

    Chance_Fate

    Joined:
    Feb 27, 2017
    Posts:
    3
    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.
     
  4. Unity_Wesley

    Unity_Wesley

    Unity Technologies

    Joined:
    Sep 17, 2015
    Posts:
    558
    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.
     
  5. Chance_Fate

    Chance_Fate

    Joined:
    Feb 27, 2017
    Posts:
    3
    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.
     
  6. Unity_Wesley

    Unity_Wesley

    Unity Technologies

    Joined:
    Sep 17, 2015
    Posts:
    558
    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.