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 /
avatar image
1
Question by Ony · May 08, 2010 at 02:04 AM · variablevariablescleanup

Easily cleaning up \ deleting unused variables?

During the course of completing a project I generally end up with several variables throughout my scripts that are declared but end up not being needed.

Is there anything out there that can run through scripts, find which variables are declared but not used, and then give a list of what and where they are?

I'm about to write my own little .exe or editor script (maybe even an UltraEdit or TextPad macro) that does that but before I spend the time I wasn't sure if something like that already existed. Anyone know of one?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Michael La Voie · May 08, 2010 at 02:21 AM

If you use C#, then there are plenty of refactoring tools available. I would strongly recommend ReSharper. It will help you do hundreds of things to improve your code, including deleting unused variables.

Its even smart enough to detect variables that are assigned to, but never read from and other esoteric cases that you may not think of if you roll your own script.

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 Ony · May 08, 2010 at 02:42 AM 0
Share

I'm using Javascript on this project so ReSharper won't work on this, but thanks for the heads-up. I'll check it out when I work more with C#.

avatar image
1

Answer by duck · May 10, 2010 at 03:27 PM

You shouldn't need any external tools to do this. Unity should show you any unused variables in the console window as an warning (with a yellow warning icon). In particular it warns you about:

  • variables which are never used at all
  • variables which are assigned, but their value is never used
  • unreachable code
  • cases where your code compiles, but is probably wrong (i.e. where a comparison will always evaluate to false)

If you double click a warning message in the console, it will open the script editor and take you to the relevant line.

Unused variables and unreachable code warnings in the Unity IDE

Edit:
Actually it seems as though these errors are only generated for C# scripts in unity, not Javascript scripts.

Comment
Add comment · Show 2 · 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 Ony · May 10, 2010 at 06:50 PM 0
Share

Is there something I need to set somewhere to have it do this? As of right now it shows neither variables which are never used at all, nor variables which are assigned but their value is never used. It shows code errors, etc. of course, but nothing in there with warnings about unused variables.

avatar image duck ♦♦ · May 16, 2010 at 01:57 PM 0
Share

Not that I'm aware of - for me, unity does this out of the box. Which version of Unity are you using? (regular/pro? iphone?)

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

No one has followed this question yet.

Related Questions

How do i call on variables from other scripts? 2 Answers

Using a string in a C# script in a .js 1 Answer

Is it possible to change a variable, into a script not assigned to any game object? 3 Answers

how to create boolean Varibles ? 3 Answers

The name 'Joystick' does not denote a valid type ('not found') 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