- Home /
Is there a way to have a data breakpoint in unity3d?
Hello there!
Very often I face the same problem: Some script is changing some value (like transform) and it would be great to have a tool to print the stack of the code that make the modification.
In Visual Studio 2013 there is an option to add a "data breakpoint" which will stop the program whenever the given value changes. Unfortunately, its for C++ only.
Usually I write a wrapper to debuglog whenever the wrapped code is accessed. However, this solution consumes time
haven't tried it myself (data breakpoint), but do you have visual studio tools for unity (unityvs)?
gjf - yes, I have it installed and I can debug with Visual Studio. Unfortunately data break point is disabled (I read in documentation that its for c++ only)
I forgot to mention - there is 'alternative way' to achieve such breakpoint, but its not working always - you just need to remove the component and wait for next nullpointer exception :D
I personally use Debug.Break with a little bit of rigging. Works okay, but requires a bit of extra labor for some uses.
Answer by ShabihDesperado · Apr 07, 2015 at 10:06 AM
An option that you have is modify the var to a private field and become a property (with get and set). In this way you can use the breakpoint in the set function.
Thank you for your answer. Is it possible to do this with default components and their var (like transforms and colliders)?
Yes but you have to make your own variable.
private var myTransform;
void Start(){
myTransform = this.transform;
}
public Transform $$anonymous$$yTransform
{
get{ return this.myTransform;}
}
It's not useful if any other script is trying to access getting the Transform component without calling the script function.
Answer by stacker3d · Aug 10, 2015 at 06:32 AM
You can right-click a breakpoint and choose Breakpoint Properties to open a dialog where you can set a condition. Some breakpoints should help you to drill down the code that acidentally modifies the properties.
Related: https://unity3d.com/learn/tutorials/modules/beginner/scripting/monodevelops-debugger
Answer by ChrisHandzlik · Nov 15, 2021 at 04:56 PM
I've put together an asset that allows you to capture/debug all thouse changes to transforms.
That's available on Asset Store.
There's an open source approach https://github.com/handzlikchris/Unity.MissingUnityEvents
PS: ressurected old thread as it still comes up in google and I believe it can be helpful to others
Your answer
![](https://koobas.hobune.stream/wayback/20220613192317im_/https://answers.unity.com/themes/thub/images/avi.jpg)