Can't get Unity Debugger to work #815
-
When I run "lua require("dap").continue()" I get this output: UnityDebug: Initializing Do anyone know what I am doing wrong? This is my current setup:
|
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 16 replies
-
please add 'path' parameter. dap can find your Unity proccess. dap.configurations.cs = { |
Beta Was this translation helpful? Give feedback.
-
@Imlimp @nagaohiroki How are you able to configure the adapter now that VSDebug has been deprecated and newer versions of Unity are using Unity for VS Code extension? |
Beta Was this translation helpful? Give feedback.
-
@yemibox51 dap.adapters.vstuc= {
type = 'executable',
command = vim.env.HOME .. '/AppData/Roaming/Code/User/globalStorage/ms-dotnettools.vscode-dotnet-runtime/.dotnet/7.0.14~x64/dotnet.exe',
args = {vim.env.HOME .. '/.vscode/extensions/visualstudiotoolsforunity.vstuc-0.9.3/bin/UnityDebugAdapter.dll'},
name = 'Attach to Unity',
}
dap.configurations.cs = {
{
type = 'vstuc',
request = 'attach',
name = 'Attach to Unity',
-- path = 'UnityProject/Library/EditorInstance.json -- not working?
logFile = vim.env.HOME .. "/Desktop/vstuc.log",
endPoint = "127.0.0.1:56912" -- from Unity Editor.log
},
} |
Beta Was this translation helpful? Give feedback.
-
instead absolute path, you can use path = vim.fn.getcwd().."/Library/EditorInstance.json", as for vstuc, it may has some optimization that cant fit in neovim based on the trace
Unlike the old debugger provided by unity,vstuc is not open-source.so it need some decompiling work. |
Beta Was this translation helpful? Give feedback.
-
Breakpoints not working (logs have a null reference exception), but I hacked together a little way to make connecting to unity more consistent (since that port number keeps changing each time you open it) local vstuc_path = os.getenv("HOME") ..
"/.vscode/extensions/visualstudiotoolsforunity.vstuc-1.0.1/bin/"
dap.adapters.vstuc = {
type = 'executable',
command = 'dotnet',
args = {
vstuc_path .. 'UnityDebugAdapter.dll'
}
}
dap.configurations.cs = {
{
name = 'Attach to Unity',
type = 'vstuc',
request = 'attach',
path = vim.fn.getcwd() .. "/Library/EditorInstance.json",
logFile = vim.env.HOME .. "/vstuc.log",
endPoint = function()
local system_obj = vim.system(
{ "dotnet", vstuc_path .. "UnityAttachProbe.dll" })
local probe_result = system_obj:wait(2000).stdout
if probe_result == nil or #probe_result == 0 then
print("No endpoint found (is unity running?)")
return ""
end
local pattern = [["debuggerPort":(%d+)]]
local port = string.match(probe_result, pattern)
if port == nil or #port == 0 then
print("Failed to parse debugger port")
return ""
end
return "127.0.0.1:" .. port
end,
}
} Running UnityAttachProbe.dll gets you output like this:
and it will give you nothing if there is no unity instance running |
Beta Was this translation helpful? Give feedback.
-
new Unity debugger is Adding filterOptions to nvim-dap's setExceptionBreakpoints made it work. and init.lua setting local vstuc_path = vim.env.HOME .. '/.vscode/extensions/visualstudiotoolsforunity.vstuc-1.0.4/bin/'
dap.adapters.vstuc = {
type = 'executable',
command = 'dotnet',
args = { vstuc_path .. 'UnityDebugAdapter.dll' },
name = 'Attach to Unity',
}
dap.configurations.cs = {
{
type = 'vstuc',
request = 'attach',
name = 'Attach to Unity',
logFile = vim.fs.joinpath(vim.fn.stdpath('data')) .. '/vstuc.log',
projectPath = function()
local path = vim.fn.expand('%:p')
while true do
local new_path = vim.fn.fnamemodify(path, ':h')
if new_path == path then
return ''
end
path = new_path
local assets = vim.fn.glob(path .. '/Assets')
if assets ~= '' then
return path
end
end
end,
endPoint = function()
local system_obj = vim.system({ 'dotnet', vstuc_path .. 'UnityAttachProbe.dll' }, { text = true })
local probe_result = system_obj:wait(2000).stdout
if probe_result == nil or #probe_result == 0 then
print('No endpoint found (is unity running?)')
return ''
end
for json in vim.gsplit(probe_result, '\n') do
if json ~= '' then
local probe = vim.json.decode(json)
for _, p in pairs(probe) do
if p.isBackground == false then
return p.address .. ':' .. p.debuggerPort
end
end
end
end
return ''
end
},
}
|
Beta Was this translation helpful? Give feedback.
please add 'path' parameter. dap can find your Unity proccess.
dap.configurations.cs = {
{
type = 'unity',
request = 'attach',
name = 'Unity Editor',
path = 'YourUnityProject/Library/EditorInstance.json'
}
}