Closed deltamish closed 6 years ago
In ObjectImporter you have some events you can register on. From documentation:
CreatedModel
event is triggered when a single model has been created and before it is imported.ImportedModel
event is triggered when a single model has been successfully imported.ImportingStart
triggered when starting to import.ImportingComplete
triggered when a single model has been successfully imported.ImportError
triggered when an error occurred while importing a model.
You can register to events before starting loading:
ObjectImporter importer = GetComponent<ObjectImporter>();
importer.CreatedModel += OnModelCreated;
importer.ImportedModel += OnModelImported;
importer.ImportError += OnModelError;
//...
The first two events can be handled by a delegate that accepts the main loaded GameObject and the absolute path:
// handle the ImportedModel event
protected void OnModelImported(GameObject loadedObj, string absolutePath)
{
// Here you can get the Renderer components in the object children and change or replace materials
MeshRenderer[] meshRend = loadedObj.GetComponentsInChildren<MeshRenderer>();
foreach (var rend in meshRend)
{
Material mtl = rend.material; // or rend.sharedMaterial to change the material itself
//...
}
}
@deltamish About your second question: unfortunately I never thought about it, I suggest to create a new issue, sharing your knowledge about Unity job system, maybe with references, so everyone can understand your proposal. I will mark it as enhancement (and I'll think about it...).
Hey Thanks a lot for the solution. Its even easier and faster this way than having a for loop and regularly check for Meshes .
and sure Ill create a new issue, But I have little knowledge on the topic
Hey,
Loved the asset. I was wondering If theres a method to attach a script or a material when loading async.
and also if there's going to be any optimization done using Unity Job system in the up coming releases
Thanks