public static Texture2D ExtractHoudiniImageToTextureFile(HEU_SessionBase session, HAPI_MaterialInfo materialInfo, string imagePlanes, string assetCacheFolderPath) { Texture2D textureResult = null; // Get the Textures folder in the assetCacheFolderPath. Make sure it exists. assetCacheFolderPath = HEU_AssetDatabase.AppendTexturesPathToAssetFolder(assetCacheFolderPath); HEU_AssetDatabase.CreatePathWithFolders(assetCacheFolderPath); // Need to pass in full path to Houdini to write out the file assetCacheFolderPath = HEU_AssetDatabase.GetAssetFullPath(assetCacheFolderPath); if (assetCacheFolderPath == null) { return textureResult; } HAPI_ImageInfo imageInfo = new HAPI_ImageInfo(); if (!session.GetImageInfo(materialInfo.nodeId, ref imageInfo)) { return textureResult; } // This will return null if the current imageInfo file format is supported by Unity, otherwise // returns a Unity supported file format. string desiredFileFormatName = HEU_MaterialData.GetSupportedFileFormat(session, ref imageInfo); // Extract image to file string writtenFilePath = null; if (!session.ExtractImageToFile(materialInfo.nodeId, desiredFileFormatName, imagePlanes, assetCacheFolderPath, out writtenFilePath)) { return textureResult; } HEU_AssetDatabase.SaveAndRefreshDatabase(); // Convert full path back to relative in order to work with AssetDatabase string assetRelativePath = HEU_AssetDatabase.GetAssetRelativePath(writtenFilePath); // Re-import to refresh the project HEU_AssetDatabase.ImportAsset(assetRelativePath, HEU_AssetDatabase.HEU_ImportAssetOptions.Default); textureResult = HEU_AssetDatabase.LoadAssetAtPath(assetRelativePath, typeof(Texture2D)) as Texture2D; //Debug.LogFormat("Loaded texture to file {0} with format {1}", writtenFilePath, textureResult != null ? textureResult.format.ToString() : "none"); return textureResult; }