FactoryCanImport returns false when it should be true
I'm writing a custom import routine and some of my importer mimics the AssetTools import routine. At one point, UFactory::FactoryCanImport is called. It takes in a filepath and returns a bool indicating whether or not the factory can handle the given file. Problem is, the default implementation returns false if the filepath has an any extension other than "t3d". Even the UFbxFactory returns false when passed a typical fbx file. When I use the factory anyway, the fbx file seems to be imported without error.
In the AssetTools module, if you step through the import routine, it saves the first factory in the array. It then iterates over all factories in the array, calling FactoryCanImport on each one, and if it returns true, it saves that factory instead and breaks the loop. However, it never returns true if it's not a t3d extension. Since the first factory in the array was saved before iterating the array, that factory gets used anyway, and it happens to be the appropriate one so it works. Is this the intended behavior? What is the point of iterating over all factories in the array if it's not a t3d extension, since the first one is always used anyway? Is there another way we're supposed to check if a factory can deal with a given file before using that factory to import it?
A lot of this code is largely out of date and due for an update. The factory is almost always chosen based on the extensions that the factory supports. See UFactory::GetSupportedFileExtensions. Usually your FactoryCreateBinary or FactoryCreateText should just return false if it cant handle the file.
answered Aug 27 '14 at 01:29 AM
Reanimating this thread after such a long time... But it's exactly the problem I have.
I'd suggest to modify UFactory::FactoryCanImport() by the following code snippet:
followed by the t3d-handling stuff. That way, FactoryCanImport just checks for the extension string (case sensitive, as I just realize) being listed in the Formats array. That array is supposed to be filled by the derived Factory classes. Is there anything, that would render that approach to be wrong? For me, it seems to be "just the right thing" (TM).
answered Feb 23 '17 at 03:19 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here