Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Yanfundi · Aug 12, 2020 at 09:22 AM · editorcontextmenu

Get All GameObject in Prefab Mode

I have a custom script that Inherit from TextMeshProUGUI and now I want to convert all of my GameObjects UI that have TextMeshProUGUI into my custom script. I have created a MenuItem and the logic for changing it. It works wonderfully. The problem is that, I wanted to be able to change the TMPUGUI in prefabs as well, but my current code only gets the GameObjects that is in the current scene. How do I / Is there a function to get all the GameObjects in Prefab Scene mode? Is there a way to detect if I'm currently in Normal Scene or in Prefab Scene mode? because I want to use 1 Menu Item that can be used both in Normal Scene and Prefab Scene mode if the way to get the GameObjects is different between modes. Thank you.

     [MenuItem("Tools/Migrate TMPUGUI to TMPLanguage")]
     public static void MigrateTMPToTMPLang()
     {
         TextMeshProUGUI[] TMPs = GameObject.FindObjectsOfType<TextMeshProUGUI>();
 
         ...
     }
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 gillemp · Aug 23, 2021 at 12:10 PM 0
Share

Did you find a solution? I am running into the same issue...

avatar image Yanfundi gillemp · Aug 30, 2021 at 01:58 AM 0
Share

nope, currently I have to manually change it.

2 Replies

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

Answer by Yanfundi · Apr 06 at 02:51 PM

Alright, after all this time, I finally found it. PrefabStageutility.GetCurrentPrefabStage(). It's using UnityEditor.Experimental.SceneManagement;

     TextMeshProUGUI[] TMPs = new TextMeshProUGUI[0];
     if (PrefabStageUtility.GetCurrentPrefabStage() != null) //In Prefab Mode
         TMPs = PrefabStageUtility.GetCurrentPrefabStage().FindComponentsOfType<TextMeshProUGUI>();
     else if (Selection.activeGameObject != null) //For changing selected only (include child). Works for prefab as well (no need to open the prefab).
         TMPs = Selection.activeGameObject.GetComponentsInChildren<TextMeshProUGUI>(); //Could use Selection.gameobjects for multiple selection, probs change TMPs to List
     else //In Scene Mode not selecting anything
         TMPs = GameObject.FindObjectsOfType<TextMeshProUGUI>();


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 GeroNL · Aug 30, 2021 at 03:07 AM

Hello, you can not find gameobect if it not exist in the scene, you need to instantiate first.


Reference : https://docs.unity3d.com/Manual/InstantiatingPrefabs.html


Hope it help

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

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

GenericMenu and ContextMenu question 1 Answer

How to add context menu on assets and asset folder? 1 Answer

Determine the Scene that is selected when using context menu 0 Answers

Extending the Project View 2 Answers

Adding to GameObject context menu WITHOUT [MenuItem(...)] 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