Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
1
Question by sarahnorthway · Dec 16, 2016 at 07:42 PM · transformpositiondebuggingbreakpointstacktrace

How to tell what method is moving an object?

I run into this at least once a week on the large established codebase I'm working with, and it makes debugging painful: something will move (transform.position changed), and I have no idea what moved it.

In C++, I'd use a data breakpoint to pause execution at the moment the position changes then look at the call stack. (Data breakpoints aren't supported in Unity)

In AS3, I'd turn position into a getter/setter function and add a stacktrace just before it is set. (Transform.position can't be overridden in Unity)

Any new ideas for figuring out what line of code is moving an object?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by ChrisHandzlik · Feb 01, 2020 at 05:23 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 displayed in a easy to use GUI.

Tool in action on Youtube alt text

That's available on Asset Store

There's also an open source component that can help: 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.


transform-changes-debugger-youtube-thumb.jpg (193.1 kB)
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image RobBrooks · Feb 01, 2020 at 05:54 PM 0
Share

Woo. Spooky. #1 thread on Google that addresses my question's most recent answer 24 $$anonymous$$utes ago...... first in over 3 years. Thanks Chris. I'll give this a shot. :)

avatar image
0

Answer by AurimasBlazulionis · Dec 16, 2016 at 08:07 PM

Unity's deep profiler can help you. Setting position calls some internal functions and it is not that cheap. If you do not have that many scripts and the position changes every frame, you will be able to spot it there.

Alternatively you can add Debug.Log line before each transform changing line. It will show the full trace of the call. But I believe if your codebase is large, it will be painful to look through each file. If you are on Linux or Mac, you can do something like egrep -lir --include=*.{js,cs} "(transform.position =)" . inside the root of the project using terminal. On Windows, something similar should be possible.

Another option is to disable one component after another and see if something happens.

Unfortunately, the internal call OnTransformChanged is not exposed so you will not be able to use that.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image sarahnorthway · Dec 16, 2016 at 08:22 PM 0
Share

Yeah the codebase is far too large and complex to use the profiler, check every reference to transform.position (in Visual Studio ctrl+shift+f searches all files) or disable every component. Just too many interconnected things and errors that cascade into other errors.

avatar image
0

Answer by sarahnorthway · Dec 16, 2016 at 08:41 PM

This is not a great solution, but I can override a component's transform with the new keyword. This only applies when the component is referenced as its subclass (MyClass), but not when referenced as its parent class (MonoBehavior), so it only works if the method I'm looking for calls MyClass.transform.position not MonoBehavior.transform.position. And it catches all references to transform which is a lot. But it's a start.

     new public Transform transform {
         get {
             Debug.Log("====== Fetching transform");
             return base.transform;
         }
     }

I tried using the new keyword to replace Transform with a dummy wrapper class so I could drill down specifically to position.get calls, but new Transform() seems to always return null in Unity.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SoraMahiro · Dec 16, 2016 at 08:46 PM 0
Share

Just as a note, calling new Transform does just that. So, unless it's given a value immediately, that will always have a null output. Yes, it's annoying.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

94 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do you access the transform of a gameobject and put it in a variable? 3 Answers

how to move the enemy in the current position of the player but only ones? 0 Answers

Camera isn't move position? Why my camera isn't change position? 0 Answers

Instantiate not spawning at correct position 1 Answer

I'm making a simple platformer and I want the position to reset when you fall off the screen 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges