- Home /
Find out what's changing the Transform.
It can be tricky to work on a project where there's already a lot of stuff made. I spend a lot of time trying to find code that makes certain objects behave some way.
I usually use System.Environment.StackTrace
to know which method is calling what, but is there a way to programmatically find out what is changing some GameObject's Transform?
By what is changing I mean which method is somehow changing the Transform fields or which GameObject may be colliding with it.
there is a way with breakpoints, in visual studio, to set a data breakpoint. If you were to set this breakpoint on the specific transform in question, then it will pause and see the stack trace any time that transform is modified. You'll have to do a little research to see how to set that in $$anonymous$$onoDevelop. Here's a place to start http://monodevelop.com/Developers/Tasks/Tools/Debugger
@Andy$$anonymous$$artin458 That would be awesome, Andy, I use visual studio. But according to this http://msdn.microsoft.com/en-us/library/350dyxd0%28v=vs.100%29.aspx it doesn't apply to C#... am I wrong??
Dang, it looks like you are correct that it can only be used in C++. I'm going to post another idea.
Answer by Catlard · Oct 03, 2013 at 07:21 AM
I'm probably a bad person for not using break points. But one way to do this is by deactivating game objects. While you're in the middle of playing the game, disable/deactivate the object that you want to investigate. Then you'll get an error that will lead you to at least one of the scripts affecting that object.
If, for example, you have a cat, and the catmover class is moving it (but you don't know what/where the catmover class is), you can disable the cat. Then, when the catmover tries to access the cat's transform, bammo. Nullref leading you directly to the catmover class.
Not sure if this was true back then but I modify the positions of inactive objects and it works fine.
Answer by ChrisHandzlik · Feb 02, 2020 at 06:02 PM
I've been in the same boat and put together a tool that weaves IL into your assembly that essentially redirects all calls from transform.postion =
(or rotation/scale) to Interceptor.Set(transform, newValue)
- this is then directly controlled by you and you can get all info necessary. Like which component exactly is doing that change, with fill stack trace and other parameters.
That's all done automatically without modifying your source code.
https://github.com/handzlikchris/Unity.TransformSetterInterceptor
PS: I know this thread is bit old but it still comes up when searching, thought it'd be good to share here.
Your answer
