How can I track down this bug of a variable being set to a value.

Someonewhere in my code a particular vector (lets call it A) which is a member variable is being set to zero.

Is there a quick way I can find out where this is happening? (i.e.rather than just putting a load of Debug.Log statements everywhere?)

I usually use Visual Studio. Then run it in the Unity Editor.

Make it a property that operates against another Vector that you don’t use, called a “backing store.”

private Vector3 backingStore;
public Vector3 TheOneYoureTryingToFigureOut
{
get { return backingStore; }
set
{
  backingStore = value;
}
}

Now you can stick a breakpoint on the assignment to backingStore above, and see the callstack where it came from.

Even if you DON’T attach the debugger, just put a Debug.Log() statement in the set {} block and you can see the callstack in the console log.

1 Like

That’s great! I didn’t think of using getters and setters.