Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Survival Shooter Stack Trace Question

Discussion in 'Scripting' started by McThunder, May 7, 2015.

  1. McThunder

    McThunder

    Joined:
    May 7, 2015
    Posts:
    4
    Hi all. So I've been working my way through the Survival Shooter tutorial and there's something that's been bothering me. In the PlayerHealth.cs script there is a public function called RestartLevel() which reloads the level. When playing the game, I see that it's being called a few seconds after the player dies. The thing is, I can't find any script that is calling this function. Does anyone know where this is being called? Is there a way to perform a stack trace and find out? I'm still new to mono develop, so excuse my noobiness.

    Thanks in advance,
    -McThunder
     
  2. McThunder

    McThunder

    Joined:
    May 7, 2015
    Posts:
    4
    Update: I used Debug.Log() to see the stack trace, and apparently there's no other script or function calling RestartLevel(). It just calls itself...How is that possible?
     
  3. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    quick skim over the learn section source code without looking at the project so this is best guess...

    Code (csharp):
    1.  
    2. // Tell the animator that the player is dead.
    3. anim.SetTrigger ("Die");
    4.  
    check the Animator component on the player. One of the animation states will run when the above trigger is set and it will likely have an animation event at the end of the animation which calls the reload function. Give the chance for the player to fall over before the level is reloaded etc.

    http://docs.unity3d.com/Manual/animeditor-AnimationEvents.html
     
  4. McThunder

    McThunder

    Joined:
    May 7, 2015
    Posts:
    4
    Thanks, you were exactly right. It wouldn't let me view the Death animation in the Animation window because "editing optimized game object hierarchy is not supported", but I checked its import settings and the event was there at the end. I looked at the settings for the event and didn't see any reference to the script, just the function name RestartLevel. So does this mean that the animation event searches all of the scripts on its parent game object for the specified function, then calls it?