My program doesn't have bugs. It just develops random features.

Difference between revisions of "User:DannyMeister"

From Unreal Wiki, The Unreal Engine Documentation Site
Jump to: navigation, search
(Created page with 'A guy who has been around for a while, but not done much.')
 
(tip about copying and instrumenting epic's classes)
 
Line 1: Line 1:
 
A guy who has been around for a while, but not done much.
 
A guy who has been around for a while, but not done much.
 +
 +
 +
 +
== Helpful snippets I don't want to forget ==
 +
If I ever get many, then I'll categorize them, and of course try to find a good place for them to fit on the wiki that's not my page.
 +
 +
=== Instrument an Epic base class for logging ===
 +
Sometimes finding the right knobs to twist and levers to pull in someone else's game or engine code can be challenging, especially when they attempt to thwart you at every turn as you try to debug!  Log messages and stack traces are both very helpful to determine what's going on, giving you insight into how you might solve your problem.  However, you can only log in your own code, and there's a good chance that the issue is in Epic's code.  Even if you try to dump a ScriptTrace(), it only shows user code rather than what may have initiated the call in Epic's code.
 +
 +
For these reasons, I will sometimes take a class that my mod is using, or inherits from, copy all of the code out of it, into a new file with a new name, inheriting from the class I copied.  Make your game use the new class instead of the old by whatever means relevant to the situation.  For example, when making custom AI for UTBot subclasses, I created a DebugBotController.uc derived from UTBot, and then had my custom AI's all derive from DebugBotController.  Now you can log freely in this class, and it'll even show up in ScriptTrace's.
 +
 +
When I really want to know ''everything'' that's going on, I sometimes instrument this debug class by using the following regex replace in jEdit to add a log message to every single function.  This example prints out the function name and the actor's current state.
 +
 +
Find:
 +
<code>(^([^\S\n]*).*(?:(?:function)|(?:event))\s+(?:\S+\b\s+)?(.*)\(.*$\s*\{(?:(?:^\s*$)|(?:\s*local\s+.+;))*)</code>
 +
 +
Replace:
 +
<code>$1\n\n$2\t`log('$3 ' @ GetStateName());\n</code>

Latest revision as of 22:17, 24 June 2014

A guy who has been around for a while, but not done much.


Helpful snippets I don't want to forget

If I ever get many, then I'll categorize them, and of course try to find a good place for them to fit on the wiki that's not my page.

Instrument an Epic base class for logging

Sometimes finding the right knobs to twist and levers to pull in someone else's game or engine code can be challenging, especially when they attempt to thwart you at every turn as you try to debug! Log messages and stack traces are both very helpful to determine what's going on, giving you insight into how you might solve your problem. However, you can only log in your own code, and there's a good chance that the issue is in Epic's code. Even if you try to dump a ScriptTrace(), it only shows user code rather than what may have initiated the call in Epic's code.

For these reasons, I will sometimes take a class that my mod is using, or inherits from, copy all of the code out of it, into a new file with a new name, inheriting from the class I copied. Make your game use the new class instead of the old by whatever means relevant to the situation. For example, when making custom AI for UTBot subclasses, I created a DebugBotController.uc derived from UTBot, and then had my custom AI's all derive from DebugBotController. Now you can log freely in this class, and it'll even show up in ScriptTrace's.

When I really want to know everything that's going on, I sometimes instrument this debug class by using the following regex replace in jEdit to add a log message to every single function. This example prints out the function name and the actor's current state.

Find: (^([^\S\n]*).*(?:(?:function)|(?:event))\s+(?:\S+\b\s+)?(.*)\(.*$\s*\{(?:(?:^\s*$)|(?:\s*local\s+.+;))*)

Replace: $1\n\n$2\t`log('$3 ' @ GetStateName());\n