• 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
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 w$$anonymous$$ch script/gameobject that keeps disabling my gameobject? i have t$$anonymous$$s gameobject that keeps disabled when i run and i couldnt figure w$$anonymous$$ch script is causing it. i tried debug.log potential scripts but im lost. is there a way to find w$$anonymous$$ch script disables a gameobject?

Comment
yosun
ina
g4borg
drorco

People who like this

4 Show 0
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
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 t$$anonymous$$s gameobject that gets disabled. T$$anonymous$$s 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
Bunny83
yosun
ina
g4borg
gipsnichmeer
olteansilvan

People who like this

6 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, 2022 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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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

Best workflow for DontDestroyOnLoad method regarding Unity Editor? 1 Answer

"GameObject.Find();" not working 2 Answers

How do I replace a game object with another one in the hierarchy? 0 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