Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
avatar image
4
Question by IllogicalGames · May 05, 2018 at 06:46 PM · gameobjectprojecthierarchyfinddisable object

How to find which script disables my gameobject

Hi guys, im stuck for 2 days now. how do you find which script/gameobject that keeps disabling my gameobject? i have this gameobject that keeps disabled when i run and i couldnt figure which script is causing it. i tried debug.log potential scripts but im lost. is there a way to find which script disables a gameobject?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by _dns_ · May 05, 2018 at 07:34 PM

Hi, it should be possible by implementing a OnDisable() method in one of the scripts that are on this gameobject that gets disabled. This will be called by Unity when another script disables the gameobject. Then, you can use the debugger (visual studio) to set a breakpoint on some line of code inside OnDisable() (just write any dummy code so you can set a breakpoint), attach the debugger to the Editor and press play in the Editor. When the breakpoint is reached, check the callstack window: it will show you all methods that were called until the code that has the breakpoint. Other option is to add a Debug.LogError("") in OnDisable: selecting the message in the console when it pops will show the callstack in the detail/lower part of the console. Using the debugger is better as you can inspect variables content and is a tool .

Comment
Add comment · Show 4 · 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 Bunny83 · May 06, 2018 at 12:59 AM 2
Share

Just adding a Debug.Log to the OnDisable method should work as well since every log in the console has a stacktrace attached.

avatar image IllogicalGames · May 06, 2018 at 08:39 AM 0
Share

Thanks man! how i never thought about OnDisable(). i've found who's the culprit ;)

avatar image Guillogika · Sep 04, 2020 at 07:53 PM 1
Share

Quick additional info: if the stacktrace is just the call to OnDisable then it is probably disabled by an animation clip

avatar image drorco Guillogika · Jan 20 at 04:20 PM 0
Share

I'm getting an empty stack trace, I've disabled all animations, and still my script component gets disabled for no apparent reason. Any more ideas?

Thanks. --- EDIT: OK, luckily, quickly after posting this I found out the culprit was an exception the class was throwing. I put that exception there and figured I'd solve it later, but apparently, exceptions in Unity might disable the script that triggers the exception, and the stack trace will be empty.

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

127 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 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

find next gameobject in hierarchy? 1 Answer

which one of the panels in unity has effect on the size of the project? 0 Answers

Find Define GameObject Problem. 2 Answers

How I can drag objects(songs) into the game(at runtime) and save it? 0 Answers

"GameObject.Find();" not working 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