Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

How make Resources.FindObjectsOfTypeAll to find unloaded objects?

Discussion in 'Scripting' started by tr1te, Apr 30, 2015.

  1. tr1te

    tr1te

    Joined:
    Sep 5, 2012
    Posts:
    38
    The simple answer is to load it. I found all files with Directory.GetFiles(). Then I choose all files name that i need. And load them with Resources.Load() then I tryed Resources.FindObjectsOfTypeAll() and again it is not finding all textures. How can i fix this?

    Code difficult to read because the function get file "mask" and I finding for files with the same name to the separator "_" in the same directory.
    For example:
    Filename_0.tga
    Filename_1.tga
    Filename_2.tga
    Filename_3.tga
    Filename_4.tga

    Code (CSharp):
    1.  
    2. function (Texture2D mask)
    3. string[] dirFiles = Directory.GetFiles( AssetDatabase.GetAssetPath( mask ).Remove( AssetDatabase.GetAssetPath( mask ).LastIndexOf( "/" ) ) );
    4.         string fileBaseName;
    5.  
    6.         for ( int i = 0; i < dirFiles.Length; i++ ) {
    7.             fileBaseName = dirFiles[i].Substring( dirFiles[i].LastIndexOf( @"\" ) + 1 );
    8.             if ( fileBaseName.StartsWith( maskBaseName ) && !fileBaseName.EndsWith("meta")) {
    9.                 Resources.Load( AssetDatabase.GetAssetPath( mask ).Remove( AssetDatabase.GetAssetPath( mask ).LastIndexOf( "/" ) ) + "/" + fileBaseName ) as Texture2D;
    10.             }
    11.         }
    12.  
     
  2. tr1te

    tr1te

    Joined:
    Sep 5, 2012
    Posts:
    38
    No one know how to find objects from resourses?