Hello Everyone again! This time I have a more general question. Is there any way to (while having pressed the play button) have the game pause and let you see exactly what line of code it was running right before pausing? I have a turret that aims at a GameObject target. And every other frame the turret believes the target is null. When playing the game, it's almost impossible to notice. However, the target isnt' supposed to be null unless the target disappears (which it isn't). I was wondering if there was a way to tell the computer "If the target becomes null, STOP and tell me the last line of code you ran." Thank you again for your time-
The simplest way is to turn on error pause and put in a Debug.LogError statement. For more versatility you can attach a debugger externally and set up break points.
Thank you. But does this work for things that aren't errors as well? My game doesn't return an error when the object is null. The only way I figured that out was by having it print it's status in the update method.
In that specific question, you won't be able to ever see the LAST line of code that was run. However, you could rewrite 'target' as a property, and intercept it AS it is being changed: Code (csharp): public Transform target { //I'm guessing it's a transform, but it can be whatever set { if (value != _target) { Debug.Log("Changing target to "+(value != null ? value.gameObject.name : "NULL") ); _target = value; } get { return _target; } } private Transform _target; Now, anytime this thing is changed, it will tell you so in the console; if you click on this in the console, you can then dig into the stacktrace and see exactly where this change was made. (Note: If the previous target's GameObject gets destroyed, the value will be, functionally, NULL, but that property will not have been called to change it. If that's what's happening, this won't help you.)
That is a beautiful idea. I like that a lot. I was able to eventually find what was going on. Thank you!