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
0
Question by Heino · Sep 17, 2013 at 09:51 AM · editorprefabs

OnWillSaveAssets causes error in saving prefabs.

I have a bit of a complex setup where I'm using OnWillSaveAssets to create prefabs of certain objects whenever a scene is saved. I'll try to give an explanation to the setup, before I describe the actual error.

Basically, a scene might consist of the following objects:

  • GameObject1

  • GameObject2

  • SpecificObjects

  • PrefabObject1

  • PrefabObject2

The objects named "GameObject#" can be any given object, which is not connected to a prefab. "PrefabObject#" can be any object which is connected to a prefab. "SpecificObjects" are a holder object for a lot of other objects, which are the objects that are being saved as prefabs in the OnWillSaveAssets method.

The problem then arises when I actually save a scene. Basically everything seems to be working fine, but we've discovered that if we remove a component on one of the "PrefabObject"s, apply the prefab and then save the scene, we get the following errors:

CheckConsistency: GameObject does not reference component Animation. Fixing.

com->m_GameObject.GetInstanceID () != 0

When this happens, the component that was removed from the prefab has now been restored on the actual prefab. So basically we've lost the changes. The above error message is from a repro where an Animation component was removed, but it happens no matter what component is removed.

I have narrowed it down to that any call to PrefabUtility.CreatePrefab or PrefabUtility.CreateEmptyPrefab will cause this error. If I don't call these methods inside OnWillSaveAssets, everything works fine. So it seems it is related to the prefab-system somehow, but the weird thing is of course that it is objects that are unrelated to the prefab creation that I'm doing, which is causing the problems.

I hope my explanation has been meaningful enough that someone can figure out what's going on and can tell me what I'm doing wrong. Is it not allowed to call CreatePrefab inside OnWillSaveAssets maybe?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Sep 17, 2013 at 10:44 AM

Maybe you used Destroy instead of DestroyImmediate ? Can't think of something else without seeing your code.

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 Heino · Sep 17, 2013 at 11:38 AM 0
Share

I know it seems a bit confusing, but the thing is that this error happens on objects I'm not even touching with my script. And I'm not calling Destroy or DestroyImmediate on anything.

I'll try to give an example. Lets say that the game object called "SpecificObjects" in the scene contains three child objects called "c1", "c2", "c3". When I save the scene, I want these three objects to be created as prefabs in a specific folder in my project. All that works fine.

But lets say there's another object in the scene, which isn't a child of "SpecificObjects", called "p1" for instance. "p1" is a prefab object and it has for instance an Animation component attached. If I then try to remove the Animation component, through the inspector, press "Apply" in the inspector and then save the scene, I'll get the error posted in my original post and the Animation component will be restored. So the error is happening on an object that I am in no way manipulating.

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

16 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

Related Questions

Mark gameobject field as changed from prefab 2 Answers

Prefab mode doesn't show prefab, still shows old scene. 7 Answers

Editor-only circular contour around prefab instances 2 Answers

Cant See More Than Two Levels Of Children In The Project Tab 1 Answer

How to make sure editor completed refreshing before running other codes? 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