Search code examples
c++unity-game-enginevectorassert

How to find out the location of a failed assert? (Calling debug-build DLL in Unity)


Writing a C++ DLL to use from Unity3D. If I build the DLL as release, I currently get some undefined behavior nonsense. If building as debug build, the following popup shows:

enter image description here

Unfortunately the error redirects into the vector class and not the place where it is actually used in my own code. I know what DLL function causes this, but I cannot find out why this happens because there is a lot of vector handling. I do suspect some multithreading issue.

However how do I find out which particular line, aka which assert failed? I do not seem to be able to catch asserts with the try-catch block.

Huge thanks in advance :)


Solution

  • Turns out it is possible to debug the Unity editor as a whole with attached DLLs.

    1. Find out where the actual editor is (in the rightclick menu of the installs tab in Unity Hub)
    2. Open that EXE with Visual Studio (literally the "Open project" selection)
    3. Go to the solutions properties -> parameters and add: -projectPath "PATH_TO_YOUR_UNITY_PROJECT_DIRECTORY"
    4. Debug -> Start Debugging (or F5)
    5. If you get an assertion etc. click "Retry".

    Step 3 is important because for whatever reason, Unity does not show the "open a project" option if started as debug and just closes itself instead. That's what made me think that external debugging is not supported.