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 Rikard · Mar 17, 2011 at 01:51 PM · instantiatetransformprefabresetreplace

ReplacePrefab() resets transforms for instanced prefabs?

Hi, I have a problem with instanced objects getting their transforms reseted back to their initial Prefab transform values. All this happens when I re-import a model that is processed through a editor script in OnPostprocessModel(). In this script I apply BoxColliders, scripts and so on. Everything works great except for the transform-problem. Here's the code snippet I think is causing the problem.

//Instantiate the loaded model in the scene temporarily to make changes to var go:GameObject = GameObject.Instantiate(model, Vector3.zero, Quaternion.identity) as GameObject;

 //Search for prefab at path
 var prefabName:String = "Assets/Prefabs/LevelComponents/GroundComponents/" + model.name + ".prefab";
 var prefab:Object = AssetDatabase.LoadAssetAtPath(prefabName, Object) as Object;
 if(prefab == null)
 {
     Debug.Log("Couldn't find any prefab with the name: " + model.name);
     Debug.Log("Creating prefab: " + model.name);
     prefab = EditorUtility.CreateEmptyPrefab(prefabName);       
 }
 else
 {
     Debug.Log("Found prefab to update. Updating: " + model.name);
 }
 //Replace prefab with the modified GameObject
 EditorUtility.ReplacePrefab(go, prefab);

 //Remove the GameObject from scene
 Editor.DestroyImmediate(go, true);

So my question is if there's a way to update a prefab with "reimport" and process the model without reseting the transforms for the instanced objects in scenes? Thanks, /Rikard

Comment
Add comment · Show 3
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 Rikard · Mar 30, 2011 at 09:17 AM 0
Share

Anyone? I'm really clueless about this.

avatar image nsxdavid · Jan 19, 2012 at 02:10 AM 0
Share

We are seeing this same problem. Worse... the object then has some sort of psychic connection to the prefab. Changing the prefab's transform immediately modifies the instances in the scene. That just ain't right.

avatar image watchoutfree · Oct 10, 2012 at 09:49 AM 0
Share

I'm having the same problem, it seems there's no way to do this. I was trying to make vertices to go back...

1 Reply

· Add your reply
  • Sort: 
avatar image
4

Answer by TMPxyz · Dec 18, 2012 at 05:56 AM

Hi, try this: PrefabUtility.ReplacePrefab(go, thePrefab, ReplacePrefabOptions.ReplaceNameBased);

Comment
Add comment · Show 3 · 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 hanfordlemoore · Jan 12, 2014 at 03:26 AM 0
Share

No one has voted on this (and I don't have rep yet to do so) but I just tried ReplacePrefabOptions.ReplaceNameBased and it worked. The existing prefabs did not move. Great job.

avatar image Trond_Tactile · May 25, 2016 at 07:48 AM 0
Share

Can confirm that this works for this intended behaviour.

avatar image pocoster · Mar 12, 2017 at 01:44 AM 0
Share

Who'd have thought all these years later and still this comment is proving mega useful... Thanks very much.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Problem with GetComponentinChildren and Instantiate 0 Answers

How to follow multiple clones positions of an instantiate prefab having a velocity ? 1 Answer

Howto set main.camera as a parent when main.camera itself is a child of a prefab 1 Answer

How do I instantiate a Prefab using a MenuItem? 1 Answer

How to make sprites instantiate based on randomly generated integer? 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