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 Bluestrike · May 22, 2013 at 11:28 AM · colliderfindlod

How can i find all *_LOD1 objects in a scene?

There is a bug where the physics act weird because the automatic LOD meshes also have many collision meshes instead of a single shared one. Basicly it makes everything more slippery then it needs to be.

Since I don't have high hopes for a fix on this matter, I want to try and have a script that automaticly disables the collision mesh for all gameobjects named *LOD1 *LOD2 and *LOD3 as that fixes the problem I have.

Now I understand how to find a gameobject with a specific name, but how can I find gameobjects with a specific part of their name?

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
Best Answer

Answer by hiddenspring81 · May 22, 2013 at 05:14 PM

Use Resources.FindObjectsOfTypeAll. This will return all of the objects that have been loaded into memory, of a given type.

 // Build a list of all Meshes that exist in memory
 var loadedMeshes = Resources.FindObjectsOfTypeAll(typeof(Mesh));
 
 foreach (var mesh in loadedMeshes)
 {
   // Find only those meshes that in LOD1, LOD2, or LOD3
   if (mesh.name.EndsWith("LOD1")|| mesh.name.EndsWith("LOD2") || mesh.name.EndsWith("LOD3"))
   {
     // Turn off the mesh collider
     mesh.collider.enabled = false;
   }
 }

Just be careful with when you call Resources.FindObjectsOfTypeAll because it's extremely expensive, computationally.

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 Bluestrike · May 23, 2013 at 08:24 AM 0
Share

Thanks, I will be using it as an editor script to quicky update all lod models in a scene.

Here is my editor script based on @hiddenspring81 his awnser for who can use it:

 class SD_Lod$$anonymous$$anager extends ScriptableWizard
 {
     var scrollPosition     :Vector2;
 
     //-------------------------------------------------------------------------------------------------------------------------------
     new function OnGUI() :void
     {
         scrollPosition = GUILayout.BeginScrollView (scrollPosition);
         GUILayout.Space (10);
     
         if(GUILayout.Button("Disable lower lod colliders")) 
         {
             EnableLodCollision(false);
         }
          
         if(GUILayout.Button("Enable lower lod collisions")) 
         {
             EnableLodCollision(true);
         }    
         
         GUILayout.Space (20);
         
         if(GUILayout.Button("Close")) 
         {
             this.Close();
         }
         
         GUILayout.EndScrollView ();
     }
 
     //-------------------------------------------------------------------------------------------------------------------------------
     @$$anonymous$$enuItem("Lod Collider manager")
     static function Init() :void
     {
         var window :SD_Lod$$anonymous$$anager = EditorWindow.GetWindow(SD_Lod$$anonymous$$anager, false, "Lod $$anonymous$$anager");
     }
 
     //-------------------------------------------------------------------------------------------------------------------------------
     function EnableLodCollision(enabled :boolean) :void
     {
         // Create an array that has all colliders in the scene.
         var colliders :Collider[] = FindObjectsOfType(Collider) as Collider[];
 
         for(var col :Collider in colliders)
         {
             // Find only those meshes that in LOD1, LOD2, or LOD3
              if (col.name.EndsWith("LOD1") || col.name.EndsWith("LOD2") || col.name.EndsWith("LOD3"))
               {
                 // Turn off the mesh collider
                 //Debug.Log(col.name);
                 col.enabled = enabled;
               }
         }
     }
 }
 

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

14 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

Related Questions

Getting Objects from CheckSphere 0 Answers

Find all objects inside box collider 4 Answers

heightmapMaximumLOD does not refresh the terrain collider? 0 Answers

Find closest point of a sprite to GameObject 2D 1 Answer

Find right mesh for collider 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