How to unload an already loaded model?
rodcibils opened this issue · 2 comments
What is the procedure for unloading an already loaded model? Can I just delete it with unity or there is something else to do with the importer?
I want to prevent the parallel loading of several models, check if a model is already loaded and, if the user wants to load a new one, unload the older and load the newer.
Thanks for develop and share this excellent tool.
Try with this procedure:
- in
ObjectImporter
, when you callImportModelAsync(...)
, inoptions
parameter you should leavereuseLoaded
tofalse
(default) - register your script to the event
OnModelmported
, so you get a reference to the imported object (see issue #24 ) and store it in a variable of your script (e.g. myLastLoadedObject) - register to the event
ImportingComplete
(e.g. create a method OnImportingComplete) so you know when the old loader is destroyed before loading a new object - In your OnImportingComplete method set a flag in your script to know that you can safely delete the current object
- before loading a new object check the above flag, if it is set then destroy the old object (e.g.
Destroy(myLastLoadedObject)
, see above) and reset your flags and variables - load the new object (
ImportModelAsync(...)
)
I think this should work, I'll wait for your feedback.
Well, in first place, thank you very much for the fast answer, it's really awesome work with a free tool like this knowing that it's developer takes care about it.
I implemented the procedure above with no issues, work as expected. I had already done some of the steps above like getting the reference of the imported object (and edit scale, position, etc.), and adding the new steps has no negative effects on that. so everything works fine at the moment.
I'll report if there's a new issue on the road.