Search Unity

Convert .blend to .fbx and keep references

Discussion in 'Editor & General Support' started by CoughE, Mar 31, 2021.

  1. CoughE

    CoughE

    Joined:
    Oct 26, 2015
    Posts:
    39
    Hello there,

    I currently have a lot of files saves as .blend, which I like to use because I can easily double click a model in unity to open it up in Blender without having to go through the import process separately. But while building my game and doing some rough tests I'm getting results of over 50X smaller file size of exporting the same file as .fbx instead of .blend, along with faster imports as the unity backed doesn't have to convert to .fbx as it does in the end anyway.

    The problem is I have hundreds of prefabs and assets which use the current .blend files and It would be an arduous process to manually reassign them to a new model.

    Does anyone know how I could change the file type of a model without losing references? Thanks for your time!
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    Personally, I find that such file size and import speed differences are trivial. I never export as FBX unless I'm posting files publicly. Double-clicking on Blender files to edit them is PURE GOLD... you will freakin' HATE your new workflow and your game development experience will be miserable, I warn you in advance. I tried it, hated it, and reverted everything to .blend files. It's just too effortless to use .blend files directly, not to mention the error-prone nature of importing and exporting each time.

    The only thing I give up is Unity cloud builds, which do NOT support Blender. But since the free / personal Unity cloud builds became so restrictive as to be completely useless, this is no longer a factor. Unity cloud build is dead to non-paying customers.

    But if you persist, whatever you do, PUT YOUR PROJECT UNDER SOURCE CONTROL FIRST!

    Unity uses an internal python script to do this conversion:

    Unity-BlenderToFBX.py


    On MacOSX it is located at:

    /Applications/Unity.app/Contents/Tools/Unity-BlenderToFBX.py


    Dunno where it is in the Windows installation, but it's there.

    You could run this script yourself (hosted under Blender3D) and transmogrify each file in place... but you would need to take steps to rename the .meta files precisely and re-include the correct GUIDs, otherwise all your prefabs and scenes using these models would break.
     
    Joe-Censored and CoughE like this.
  3. CoughE

    CoughE

    Joined:
    Oct 26, 2015
    Posts:
    39
    Thank you for the words of warning @Kurt-Dekker. I'm glad to know there is a method.
    I am mainly looking at it for the actual distributed build size of the game, which I have a high priority of keeping it as low as possible. I think it's an underlooked area for ease of entry into your game, if its a small file its of little consequence for users to download it if they are on a data cap or slow connection, and less likely to remove your game due to needing space and might jump back into it later, but that's a whole other talk.

    I suppose I will wait until the game is near completion to convert them to .fbx, even though it will be quite a pain! If only we had double click to open on .fbx :(
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    Are you sure there is a meaningful difference? I mean it's still the same number of points and triangles!

    The only thing I can think of is that I remember hearing that Unity "alembifies" the animations from Blender: it expands your sparse array of keyframes into a keyframe every frame. I almost NEVER import my animations from Blender, but rather create the animations in Unity, so this doesn't affect me.
     
  5. CoughE

    CoughE

    Joined:
    Oct 26, 2015
    Posts:
    39
    Yes i've done a bunch of testing recently and its clear the actual build size is smaller when you use .fbx instead of .blender. Almost all of my models do not have animations, they are just static objects. In the backend it is indeed all vertices, but I guess .blend files have a stupid amount of bloat.
    Just now I opened up blender and saved a completely empty project.
    .Blend -> 728kb
    .fbx -> 3.90kb.
    Thats 186X file size increase!

    Its common knowledge that unity converts your .blend to a .fbx in the backend, but I assumed this would be done before the build, but that doesnt seem the case. I've verified this by converting my models one at a time and creating a build after each one and the file size does go down by a fair bit. I also verified it with Asset Hunter Pro.
     
  6. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    The issue could be that the FBX conversion you used for testing is more efficient than the FBX conversion Unity uses internally, leading to different resulting FBX sizes. But if @Kurt-Dekker 's solution works, you'll know quickly if that is the case.
    There's several other good reasons to want to switch out your .blend files. If you decide you want to sell parts of your game on the Assets Store, Unity doesn't allow .blend files. If you are working on a team project, especially a large team, using .blend files means everyone on your team needs to install Blender even if their work has nothing to do with modeling.
     
    CoughE and Kurt-Dekker like this.
  7. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    Oh that size doesn't matter! Unity does not ship hardly any of your files unmodified.

    They are all hoovered in, studied, ground up into a fine pink mist, then seasoned according to taste, pressed back together in juicy pellets of high performance binary goodness before they make it into your build.

    I just made a 62x62 grid in Blender, exported it as .blend, .fbx and .obj, and then built it. Here's what the build report said:

    Used Assets and files from the Resources folder, sorted by uncompressed size:
    224.5 kb 0.5% Assets/Resources/grid_obj.obj
    224.4 kb 0.5% Assets/Resources/grid_blend.blend
    224.4 kb 0.5% Assets/Resources/grid_fbx.fbx


    Essentially identical in final output.
     
    CoughE and Joe-Censored like this.
  8. CoughE

    CoughE

    Joined:
    Oct 26, 2015
    Posts:
    39
    I created a test scenario that mirrors your results. Empty unity project, one build with a default cube as a .blend and another as a .fbx. It does indeed come out to the same file size. However, in my large main project I was able to see a considerable gain (about 50kb up to even 2mb) reduction per .blend file I remade as .fbx. Again, without animation.

    This is strange, so it might not be the underlying mesh data, maybe something to do with multiple .meta files or other metadata that is linked to a .blend instead of .fbx in multiple ways? Because there is a very clear file size reduction in my builds.
     
    Joe-Censored likes this.
  9. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    Very interesting. I speculate it is the animations... try exporting a version of your game (obviously broken) with animations NOT imported (checkbox in the import).
     
    CoughE and Joe-Censored like this.