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
0
Question by colinday · Oct 19, 2016 at 10:54 PM · editorinspectorserialization

How to make a serialized editor only field

Just like the title says, I need a class member that is editable in the inspector, is saved and loaded in the .prefab file when working in the editor, but for a player build that field does not exist in the runtime.

This other Unity answer is the closest thing I could find: http://answers.unity3d.com/questions/155662/howto-editor-only-properties.html

The #ifdef sounds like what I want if it weren't for the fact that Unity is throwing an error for him that for the player build that is requiring that the serialized field be present ... and the "answer" to that question isn't what I want because by making it non-serialized it will never be saved in the prefab even when working in the editor.

My use case for this is for my localized text objects. I would like to have a string field for localization houses called "Context" which can describe the use case of the string to remove ambiguity when translated.

I know I could store localization data somewhere else, and there's a lot of ways to do it ... but it makes so much sense to keep all of the localization data with the text object itself for a million reasons, we just need persistent, editor only data to do it.

I'd love something that could like like the following if the ideal #ifdef solution is not possible, the field might still be there but at least wouldn't have any data for a player build:

    public class Translation : MonoBehaviour
    {
        [SerializeEditorOnly]
        public string Context;  // explanation of string context (editor only)
        public string English;  // english text
        public string German;   // german text
    }
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 Adamcbrz · Oct 19, 2016 at 11:19 PM 0
Share

Could you use

 #if UNITY_EDITOR
 [SerializeField]
 #endif
 private float editorOnlyVar;

It seems better to just remove the variable but that might do what you want.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by watsonsong · Jun 29, 2017 at 12:04 AM

I am seeking a way for SerializeEditorOnly. use UNITY_EDITOR define on the field will cause a lot of error report.

Comment
Add comment · 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
0

Answer by YoungDeveloper · Dec 07, 2017 at 10:25 PM

Only way to do i found

 #if UNITY_EDITOR
     [SerializeField]
 #endif
     private string _myField = string.Empty;


Personally i usually group it with #region tag in visual studio to make it more readable

     #region EDITOR-ONLY Serialized
 #if UNITY_EDITOR
      [SerializeField]
  #endif
      #endregion
     private string _myField = string.Empty;

Here's the result alt text

Comment
Add comment · 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

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

71 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

Related Questions

[Solved]Why doesn't my ScriptableObject based asset save using a custom inspector ? 1 Answer

'Unsupported type' error in custom editor script 4 Answers

Why doesn't my ScriptableObject save using a custom EditorWindow? 3 Answers

Displaying System.objects not serialized by Unity in a Custom Editor 0 Answers

Serializing list of base and derived classes with custom inspector 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