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
1
Question by irrationalistic · Sep 17, 2012 at 11:10 PM · prefabserializationinstance

Prevent Property from Serializing In Prefab but not on Instances

Trying to figure out if there's a way to prevent prefabs from receiving "apply" on certain variables in a script? I want it to have a property with a default value, but when I edit an instance in the scene and click "apply" the field stays bold and doesn't save to the prefab? Possible?

Comment
Add comment · Show 6
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 Paulo-Henrique025 · Sep 17, 2012 at 11:28 PM 0
Share

Why not a private field?

avatar image irrationalistic · Sep 17, 2012 at 11:29 PM 0
Share

Instances have to be able to modify it.

avatar image Paulo-Henrique025 · Sep 17, 2012 at 11:36 PM 0
Share

I have a workaround, but i think it's not the right thing to do, I'll post it as an answer. Edit: $$anonymous$$y workaround didn't work, sorry. But you can have a gameobject that hold this data to all your objects and them access it.

avatar image irrationalistic · Sep 18, 2012 at 02:27 PM 0
Share

Bummer, but thanks for checking! I was hoping for some sort of attribute that would allow the property to show in the editor but not serialize for anything but instances.

avatar image Paulo-Henrique025 · Sep 18, 2012 at 03:37 PM 0
Share

$$anonymous$$aybe Nested Prefabs can help you, a prefab with two other prefabs inside, one is the instance variables, which you never apply and the other is the shared variables which you can apply. Anyway it's confusing haha.

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by vkidd · Sep 18, 2013 at 11:57 PM

I've been trying to figure this out as well. It would be great to have a flag like [System.NonSerialize] to make a public variable non-prefab serializable. I come across this use case very often; where many prefab instances have 99% of the same setup, but need some scene specific tweaking. Making those changes is risky because someone hitting apply prefab will wipe them on all instances.

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 gjh333 · Nov 15, 2018 at 02:41 PM

Came across this problem recently. Try this:

 using UnityEditor
 
 [ExecuteInEditMode]
 public class DontCommitPropertyA : MonoBehaviour, ISerializationCallbackReceiver 
 {
   public string PropertyA;
   public string PropertyB;
 
   OnBeforeSerialize() 
   {
     if (PrefabUtility.GetPrefabType(gameObject) == PrefabType.Prefab)
     {
       // Here you can reset values if the object is a source prefab
       PropertyA = "";
     }
   }
   
   OnAfterDeserialize()
   {
   }
 }

You may want to wrap some of this code with ifdefs for runtime. This works for me :)

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

13 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

Related Questions

When does the "InstanceID" get assigned, and does it seralize with the Object? 2 Answers

Affect All Instances Of A Prefab 3 Answers

How to remove a specific instance of a prefab from List? 1 Answer

Gameobject missing camera when instance prefab 3 Answers

How can I set the material on an instance after creating it? 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