Aller au contenu


The CoreDebug namespace contains functions that may be useful for debugging.

Class Functions

Class Function Name Return Type Description Tags
CoreDebug.DrawLine(Vector3 start, Vector3 end, [table optionalParameters]) None Draws a debug line. optionalParameters: duration (number), thickness (number), color (Color). 0 or negative duration results in a single frame. None
CoreDebug.DrawBox(Vector3 center, Vector3 dimensions, [table optionalParameters]) None Draws a debug box, with dimension specified as a vector. optionalParameters has same options as DrawLine(), with addition of: rotation (Rotation) - rotation of the box. None
CoreDebug.DrawSphere(Vector3 center, radius, [table optionalParameters]) None Draws a debug sphere. optionalParameters has the same options as DrawLine(). None
CoreDebug.GetTaskStackTrace([Task task]) string Returns a stack trace listing the Lua method calls currently in progress by the given Task. Defaults to the current Task if task is not specified. None
CoreDebug.GetStackTrace() string Returns a stack trace listing all actively executing Lua tasks and their method calls. Usually there is only one task actively executing at a time, with others in a yielded state and excluded from this trace. Multiple tasks can be included in the trace if one task triggers an event that has listeners registered, or if a task calls require() to load a new script. None
CoreDebug.ToString(value) string Returns a string representation of the given value. By default this will return the same result as Lua's built-in tostring() function, but some types may return additional information useful for debugging. The format of strings returned by this function is subject to change and should never be relied upon to return specific information. None


Example using:




Core contains several useful functions for drawing in the 3D world, that are intended for use when debugging. If you are trying to visualize values in a 3D world,

local propCubeTemplate = script:GetCustomProperty("CubeTemplate")

local myProjectile = Projectile.Spawn(propCubeTemplate,
    Vector3.New(500, 0, 200), -- starting position
    Vector3.New(0, 1, 1))     -- direction
myProjectile.speed = 500
myProjectile.lifeSpan = 3
myProjectile.gravityScale = 0.25

-- This function will draw some debug graphics around the projectile ever 1/10 second:
    while Object.IsValid(myProjectile) do
        local pos = myProjectile:GetWorldPosition();
        CoreDebug.DrawSphere(pos , 50, {
            duration = 2,
            color = Color.GREEN

        CoreDebug.DrawLine(pos, pos  + myProjectile:GetWorldTransform():GetForwardVector() * 50, {
            duration = 2,
            color = Color.WHITE,
            thickness = 3

        CoreDebug.DrawBox(pos, Vector3.New(50), {
            duration = 2,
            color = Color.BLUE,
            thickness = 3


See also: CoreObject.GetCustomProperty | Projectile.Spawn | Vector3.New | Task.Spawn | Object.IsValid | Color.GREEN | Transform.GetForwardVector

Example using:



When debugging, it can often be useful to see exactly which code is executing, and which code called it. A "stack trace" will give you this information. It is a list of every function on the call stack.

This sample shows how to get and print out the stack traces. They will be slightly different depending on which thread is examining them.

local taskStackTrace
local otherTaskStackTrace
local generalStackTrace

function Function_A()

function Function_B()

function Function_C()
    taskStackTrace = CoreDebug.GetTaskStackTrace()

local otherTask = Task.Spawn(Function_A)

otherTaskStackTrace = CoreDebug.GetTaskStackTrace(otherTask)
generalStackTrace = CoreDebug.GetStackTrace()

print("Stack trace, as viewed from within the task:")
print("Stack trace, as viewed from the main thread:")
print("General stack trace:")

See also: Task.Spawn | CoreLua.print

Dernière mise à jour: 9 février 2022