Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by Slider_j · Jul 23, 2014 at 06:11 AM · bugcompiler

Bug hunting in the code...

is there a way to put a watch on a variable or array to find out what process is writing to it?

At present i have a "database" (a list of a couple of thousand items) that should be getting used as a reference ONLY, never written to, once it's set up. i then have a second list (the inventory) that is getting read from and written to often. But for some reason when i update an item in the inventory it updates the refernce database and it shouldn't do this. I want to track down which line of code is doing the "write to the database" command. I have looked though ALL the code on the project and can't find anything that looks to be causing this behavior! anyone got any ideas? please?

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
0
Best Answer

Answer by Tehnique · Jul 23, 2014 at 06:15 AM

For a variable, you can make accessors for it (get/set), put a breakpoint in the setter, and look at the callstack when the breakpoint is hit.

Comment
Add comment · Show 3 · 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 SirCrazyNugget · Jul 23, 2014 at 06:48 AM 0
Share

You could create a property for getting the variable(s) and ensure all calls now reference this, then trace the stack to find each calling function within the get / set accessor.

previous:

 List<items> databaseVariables;

modify to

 List<items> _databaseVariables;
 List<items> databaseVariables {
   get { return _databaseVariables; }
   set { _databaseVariables = value; }
 }

This should hopefully make no changes in your code (you'll need to name the variables correctly but here's how the accessors should look).

Then change the get accessor to do additional requirements

 using System.Diagnostics;
 using System.Reflection;
 
 get {
   StackTract st = new StackTrace();
   $$anonymous$$ethodBase mb = st.GetFrame(1).Get$$anonymous$$ethod();
   Debug.Log("Get Accessor, Calling function - " + mb.Name);
   Debug.Break();
   return _databaseVariables;
 }


Hopefully this will give you a little insight into using Diagnostics, Reflection and Accessors to help some debugging.

avatar image Slider_j · Jul 23, 2014 at 06:51 AM 0
Share

thanks i'll have to have a look at how to do that! any links to ttorials on how to do that?

avatar image Slider_j · Jul 23, 2014 at 06:56 AM 0
Share

scrub that, found it (http://unity3d.com/learn/tutorials/modules/intermediate/scripting/properties) VERY helpful thank you so much! :)

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

my mistake or bug? Unity compiler error 0 Answers

Microsoft vs Mono C# compiler initialisation differences. Is this a bug in Mono? 2 Answers

Bug with Unity Compiler with Lambdas? 0 Answers

Possibly fake errors in Unity 1 Answer

Targetting script bug. (Javascript) 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