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.

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.

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.

152127-transforsetterinterceptorworkflow.gif

PS: I know this thread is bit old but it still comes up when searching, thought it’d be good to share here.