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
2
Question by oliver-jones · Jun 22, 2016 at 07:34 PM · prefabeditor-scriptingeditorwindowmodifyprefabutility

PrefabUtility - Check if Changes have been made to Prefab?

Hello,

I'm working on an EditorScript Window to help with my workflow within Unity. I want to be able to check if a prefab within the Scene has been modified in any way (such as a child of the prefab has been moved slightly).

Basically - I want to be able to tell the developer that a specific prefab within the scene has been modified but NOT applied, and from then, it will alert the developer to Apply the prefab before Removing it from the scene.

I am able to check if the Prefab has been Applied (or Updated) by 'PrefabUtility.prefabInstanceUpdated' which is also useful to me, but not for this particular case.

Is there something like this that exists? :

 //reference to the prefab within the scene
 GameObject _scene_prefab;
 
 void GUI(){
 
    if(PrefabUtility._HasBeenModified_(_scene_prefab) == true)
       Debug.Log("Prefab has been modified");
    else
       Debug.Log("Prefab has not been modified");
 }

Thanks.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by edwardrowe · Aug 31, 2016 at 04:01 PM

As u/danilonishimura suggested you can use GetPropertyModifications to get a list of modifications, though that won't give you the complete picture for instances in scenes.

Since you place prefab instances into scenes (that's what they're for), they will always have their Transforms modified. If you look, you'll see position is always bold in the Inspector, even if it matches the parent. Same with RootOrder (transform sibling index).

Another thing it won't tell you is if you add a component, or add a transform to one of the children.

Unfortunately, there's no Unity function that I've found to tell you if it's been modified outside of that. The only way I know to fix it is to write your own. If all you care about is PropertyModifications, it's easy enough to use the suggested function in PrefabUtility, and ignore the transform properties:

 var propertyModifications = PrefabUtility.GetPropertyModfiications(gameObject);
 foreach (var propertyModification in propertyModifications)
 {
     if (modification.target.name == gameObject && 
               modification.propertyPath == "m_LocalPosition.x")
     {
              // Do not consider this as a modification, since it's a modification on the root's transform.
     }
  }

Something like that.

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
2

Answer by danilonishimura · Jun 23, 2016 at 03:31 PM

Check out the docs https://docs.unity3d.com/ScriptReference/PrefabUtility.html I think what you're looking for is the GetPropertyModifications method.

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 oliver-jones · Jun 24, 2016 at 08:40 AM 0
Share

Thanks, I saw this - but I don't actually know how to implement it? The documentation is very weak.

avatar image Bunny83 oliver-jones · Jun 24, 2016 at 08:59 AM 1
Share

Well, it should be pretty straight forward. You pass a reference to a prefab instance and the method returns a list of differences compared to it's prefab.

It returns an array of Property$$anonymous$$odification instances. Each element represents a modification. Since you're only interested in if there is any modification you might be able to just check the legnth of the array. However it's possible that a different position of the object counts as modification as well.

avatar image
-1

Answer by Landerk · Jun 24, 2016 at 05:02 AM

When you change a property of a prefab, it will show bold in the Inspector. Once the change is applied, it goes back to normal. This can be hard to see, though, so I like the idea of a Debug.Log message.

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

59 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

Related Questions

Viewpport for Custom Editor 1 Answer

Can I create a child gameobject on a prefab with an editor script 2 Answers

Editor Script: Linking GameObjects to public script variables resets when playing. 1 Answer

How do I change the name of the prefab in the prefab folder with code? 0 Answers

Why is PrefabUtility.IsPartOfAnyPrefab(gameObject) returning false even though the object is a prefab? 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