How to figure out what's moving my GameObject?

I have a GameObject as part of a complex scene with a handful of interconnected parts, that's moving when it shouldn't be. I've tried running under the debugger and setting breakpoints on all of the script points that are supposed to move its Transform, and ensured that none of them are firing. There seems to be some "spooky action at a distance" going on, some rogue script doing something I don't want it to be doing, but I can't for the life of me figure out where it is.

What I'd really like is some way to set a "breakpoint" on the object's Transform that will break me into the debugger when it gets moved by any script, but that doesn't appear to be supported. Is there any way to figure out exactly what it is that's moving my object around when it shouldn't be?

(And before anyone says "trial and error, disable components and see when it stops moving," I already know exactly which component to disable to make it stop moving. Unfortunately, that isn't helping track down the problem because the movement isn't coming directly from that component's MonoBehaviour script.)

• We love to help (and get help) but it is helpful to be able to visualize your situation. Please provide as many screenshots, animated gifs, code snippets and/or project files as you reasonably are able. People don't like to download and open huge projects though so the more you can explain with images and gifs, the better – hatinacat2000 Oct 16 '19 at 8:17

Replace all instances of transform.position = and transform.localPosition = with a custom extension method:

public static class ExtensionMethods {

public static void SetPosition (this Transform transform, Vector3 position) {
if (transform.gameObject.name == "foo") {
Debug.Log("foo is being moved!");
}
transform.position = position;
}

public static void SetLocalPosition (this Transform transform, Vector3 localPosition) {
if (transform.gameObject.name == "foo") {
Debug.Log("foo is being moved!");
}
transform.localPosition = localPosition;
}

}


You can then call transform.SetPosition() or transform.SetLocalPosition().

So transform.position = somePosition; would be replaced with transform.SetPosition(somePosition);, and you'll get a stack trace from Debug.Log within.