How can you track who changes the Transform values of an object on the scene? There are answers on the Internet, but there they basically consist in wrapping the Transform at the beginning of the project into properties that can be logged. But the project is already big and there is another way to find out who is changing the values of my Transform?
1 answer
Surprisingly, it is very simple!
Enough to use extensions for classes and turn on wit!
Your actions will consist of three stages:
Create a TransformHelperLog script and hang it on the object you want to monitor. (you can not write anything in it)
Create a script under the name TransformExtensions (its code will be presented below)
In your entire project, replace the appeal to the transform
.transform => .GetTransform()using the key combination (ctrl + shift + F)
The TransformExtensions script looks like this:
public static class TransformExtensions { public static Transform GetTransform(this global::UnityEngine.Transform transform) { if(transform.GetComponent<TransformHelperLog>() != null) { Debug.Log("It's moving! " + transform.name); } return transform; } } An example of a modified treatment somewhere in different scripts:
void Update () { //someObject.transform.position += Vector3.left * Time.deltaTime; //было someObject.GetTransform().position += Vector3.left * Time.deltaTime; //стало } Further on, you can find out who changes the Transform. Once you find someone who changes your transform, you can return the appeal to the transform in the original version.