x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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?

Product Version: Not Selected
Tags:
more ▼

asked Aug 05 '14 at 03:11 PM in Using UE4

avatar image

TriangularMann
1 1 2

avatar image antithing Jul 22 '15 at 04:14 PM

Hi there, I am stuck trying to implement a UFactory for importing fbx models. How would you feel about sharing your solution to this? I will buy you a drink and sing your praises far and wide. thanks!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

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.

more ▼

answered Aug 27 '14 at 01:29 AM

avatar image

Matt STAFF
451 11 4 8

avatar image TriangularMann Sep 26 '14 at 05:43 PM

Thanks for that bit of clarification. I ended up leaving out the inner loop entirely and always using the first factory found that supports the given extension. It doesn't feel totally comfortable since I'm not sure how to guarantee the first factory found with that extension will always work, but it works at least on the particular types of assets I'm importing.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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:

 bool UFactory::FactoryCanImport( const FString& Filename )
 {
     bool CanImport = false;
     FString FileExtension = FPaths::GetExtension(Filename);
     for (const auto& Format : Formats)
     {
         const int32 DelimiterIdx = Format.Find(TEXT(";"));
         if ((DelimiterIdx != INDEX_NONE) && (Format.Left(DelimiterIdx) == FileExtension))
         {
             CanImport = true;
             break;
         }
     }
 
     if (CanImport && FileExtension == TEXT("t3d"))
 

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).

more ▼

answered Feb 23 '17 at 03:19 PM

avatar image

asuessenbach
11 2

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question