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
1
Question by Nerull22 · May 02, 2017 at 08:56 PM · childprojectchild objectassetdatabaserename

Renaming Child Assets in Project

I'm looking to see if it's possible, and if so then how to rename an asset in your project that exists as a child of another object.

I am currently using "AssetDatabase.AddObjectToAsset" API to add an object as a child of another object. But after that occurs I want to have the ability to rename that child object. Can I do this? How would I do this?

As a note, I do not want to destroy the object and then recreate it with a new name, as I want to use these as references on other objects.

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

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Ash-Blue · Aug 10, 2017 at 05:05 AM

You can easily change the name of a nested asset with a simple custom editor script.

 using UnityEditor;
 using UnityEngine;
 
 namespace MyNamespace {
     [CustomEditor(typeof(MyScriptableObject))]
     public class MyScriptableObjectEditor : Editor {        
         public override void OnInspectorGUI () {
             target.name = EditorGUILayout.TextField("Name", target.name);
             
             base.OnInspectorGUI();
         }
     }
 }
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 manuege · Feb 18, 2020 at 05:19 PM 1
Share

I did this and works ok. But the change is not reflected immediately in the project hierarchy, I need to collapse the parent asset and expand it again to make the change visible. Any way to do it immediate? thanks.

avatar image Anisoft manuege · Feb 19, 2020 at 02:09 AM 0
Share

Experiencing the same issue, strange.

avatar image Ash-Blue manuege · Dec 20, 2020 at 01:38 AM 0
Share

Yeah Unity's project asset window isn't refreshing nested objects unless they recompile. Calling refresh doesn't even work. Definitely seems like a bug as the serialization seems fine.

avatar image
-1

Answer by N1warhead · May 03, 2017 at 02:51 AM

         // 0 I believe would be the parent, just increment up 1 each time.
         transform.GetChild (0).name = "SomeNewName";
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 toddisarockstar · May 03, 2017 at 02:44 AM

         GameObject gme;
     void Start() {
            //get a unique parent or child;
         gme = gameObject.Find ("some parent object name");

             // lookup a child and rename like this:

         gme.transform.Find ("original name of child").name = "some new name";
 
         //find a child of a child like this:
 
         gme.transform.Find ("name of child/child of a child").name = "some new name";

}

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 Nobody1 · Jul 10, 2017 at 02:07 PM

@Nerull22 If you're using a custom Editor script, you can use the Editor script's "target" reference to rename a Child Asset while it's inside its Parent Asset.

From within the ItemEditor script, just use:

 target.name = newName;
 AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath((Item)target));

Where "Item" is the class of the Child Asset, and "newName" is the name you want to assign to the Child Asset.

The 2nd line reimports the asset, and doesn't seem to be strictly necessary, but if you don't use it, you won't see the name change in your "Project" view until you save Unity manually.

Note: The "target" reference is just a reference to the Object that the Editor script is targeting. I imagine that if you changed the Child Asset's .name value via another reference it would also work, but I haven't tested this.

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 Ash-Blue · Aug 10, 2017 at 05:01 AM 0
Share

Great idea, but if performance is an issue constantly hitting ImportAsset makes Unity extremely slow. Not great if an input prompt is being actively monitored.

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

72 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 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

A Constantly Updating Child Check 1 Answer

Renaming a child within code. 1 Answer

How do I register undo for the moving/renaming of a folder along with the assets contained? 0 Answers

Make child's transform independent of parent 1 Answer

Get child component of a prefab to reference with another 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