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
3
Question by PsychoDuckArcade · Apr 06, 2015 at 09:54 PM · variablereferencevaluepublicrename

How do you rename a public variable and keep object references/values?

Whenever I rename a public variable, I lose all values/references of that variable in all objects with that component.

What's the unity way to rename public variables? I guess it's not with the IDE (unless monodevelop doesn't have this problem, I'm using visual studio).

Comment
Add comment · Show 1
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 PsychoDuckArcade · Apr 06, 2015 at 10:14 PM 0
Share

Lol thanks, that WOULD fix the issue, but I don't want to use properties for every variable just so I can rename them later..

There must be a proper way to do this in unity. I'd be very surprised if there wasn't.. (If not I'd rather try writing an editor script for it before resorting to using properties for everything.)

1 Reply

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

Answer by PsychoDuckArcade · Apr 06, 2015 at 10:29 PM

I found a solution that's still quite tedious for simply renaming a variable but for as often as one needs to rename a variable it's worth it and works perfectly.

I found the attribute [FormerlySerializedAs("yourVariablesPreviousName")] in the UnityEngine.Serialization namespace.

1) Place the attribute before the variable you wish to rename.

2) Rename the variable and save changes.

3) Switch to the inspector, wait for the name to change, it will have reserialized with the new name and keep all values and references.

4) Remove the attribute (probably optional).

Comment
Add comment · Show 5 · 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 cubrman · Feb 11, 2017 at 04:30 PM 0
Share

$$anonymous$$an that is SOOO awesome. I would never have believed there exists an answer. Jesus that is so fricking usefull, thanks A LOT!

avatar image -RaganorK- · Jun 15, 2017 at 06:58 AM 0
Share

Perfect !!! Absolute genius.

avatar image EvangelosBilis · Dec 03, 2018 at 09:02 AM 0
Share

Worked like a charm. Thank you!

avatar image JukeBoxDelta · Jun 26, 2020 at 08:18 PM 0
Share

Hmm, didn't work with me in 2019.3.10.

avatar image Wellmann · Jul 22, 2021 at 12:01 PM 0
Share

For reference https://blog.unity.com/technology/rena$$anonymous$$g-serialized-fields

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

25 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

Related Questions

Static and Coroutines help 2 Answers

Maintain variable values while changing levels 1 Answer

Modify a variable inside a game object from other object. 1 Answer

Creating a Prefab and Keeping Original Objects Script Information 0 Answers

Assign a random value to var personality" upon asset creation (Java) 1 Answer


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