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
3
Question by vexe · Mar 03, 2014 at 01:18 AM · editorprefabinstancerename

Changing a prefab's name (via the editor) doesn't apply the new name to the prefab's instances?

I just noticed that if I change the name of a prefab, the new name won't be applied to the prefab's in-scene instances. That's not what I would expect. Same thing going the other way around, if I change the name of one of the instances of the prefab and hit apply, the prefab's name will remain.

So how can I reflect the changes to the prefab instances when I rename it?

Thanks!

Comment
Add comment · Show 2
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 iHaveReturnd · Mar 03, 2014 at 01:19 AM 0
Share

Someone on our $$anonymous$$m wrote a rena$$anonymous$$g extension into unity because we had the same issue. I can ask him about letting you use it but not sure what he'll say since he is planning on packaging that with some other tools to sell on the asset store.

Saying this just to let you know that's the only way around it we found.

avatar image vexe · Mar 06, 2014 at 02:21 PM 0
Share

Hey @iHaveReturnd I noticed after a while that sometimes it works, sometimes it doesn't - I explain when it doesn't in my answer. Thanks for your offer but I wasn't looking for a hack actually (it's very trivial to come up with a work-around), I thought there was something already built-in, a setting or something.

1 Reply

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by vexe · Mar 06, 2014 at 02:19 PM

It seems that, if I manually change the name of one of the instances of a prefab, and then rename the prefab itself, the new name won't be applied to the instance that I renamed.

If I don't mess around like that, i.e. I be a good boy, instantiate the prefab, (by drag-n-drop or code) - and then rename the prefab (without messing with its instances names) - everything will work nice and cozy.

I didn't like this really, so I wrote this small hack, which forces all the instances of the prefab, to have the same name as the prefab - but it forces you to rename from the prefab, not the instances.

Just stick it onto your prefab's instances that you want their names to be connected to the prefab's name:

 using UnityEngine;
 using UnityEditor;
 
 [ExecuteInEditMode]
 public class PrefabNameUnifier : MonoBehaviour
 {
     [SerializeField] [HideInInspector] GameObject prefab;
     void OnEnable()
     {
         if (PrefabUtility.GetPrefabType(gameObject) == PrefabType.PrefabInstance) {
             prefab = PrefabUtility.GetPrefabParent(gameObject) as GameObject;
             EditorApplication.update += CheckForNameChange;
         }
     }
     void CheckForNameChange()
     {
         if (prefab.name != name) {
             print("Changing instance name from: " + name + " to " + prefab.name);
             name = prefab.name;
         }
     }
 }

Since this MB will be used only in the editor, you have to wrap everything with "#if UNITY_EDITOR" "#endif" - one might think it'll be better to just place it in the editor folder, but unfortunately it won't be visible then (one can't attach it to a GO)

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 gresolio · May 24, 2016 at 07:00 PM 0
Share

Thanks, very useful example. One question: Is it possible to achieve the same, but without adding an extra script to the GameObject? I mean somehow extend the inspector via Editor scripting, that every GameObject in the scene execute this "prefab name check" while we inspect the GameObject in Editor. (According to this topic, it's not a good idea to replace internal classes "GameObjectInspector" or "TransformInspector", because it overrides Unity's implementation of their custom inspector. $$anonymous$$aybe there is a solution to extend them, not to replace).

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

22 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

Related Questions

How can I link a GameObject instance to a script variable in a Prefab using the editor? 1 Answer

changing a bool in a prefab doesn't change in it's instance. 2 Answers

Gameobject missing camera when instance prefab 3 Answers

Destroy an instance of a prefab 1 Answer

Why do prefabbed meshes go missing whenever I pull an update from Unity Collab? 0 Answers


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