top of page

Blender to Unity and Playmaker | Part 3: Importing to Unity

Video transcript :

Blender to Unity and Playmaker | Part 3: Importing to Unity

Previously we created the 3d model, the material and the animation. In this part we’re going to bring all of that we’ve created in Blender before to Unity.

Importing to Unity

Lets open Unity now. I’m not going to discuss how to start a new project in Unity as I assume you already know how to do this already. Now to import blender 3d models along with its materials and its animations to Unity, is actually very easy. You simply put your blender file inside the project’s asset folder. So you don’t really need to export them to FBX manually. Unity will handle this for you. There is just one thing you need to make sure and that is Blender software needs to be installed in your system. Why? Because Unity actually use blender software to import blender scene files. I’m using the same computer here where I use both Unity and blender so I should be fine -in sha Allah-. Lets copy the blender file now. As you can see I already prepare an empty folder in here. Open file explorer and copy this blender file. Browse to the project folder and then paste it in here. Okay. Now notice when we go back to Unity. Unity will detect that there is a new file copied to the project folder. Unity will try to convert it into an FBX format, which is a format widely used for game creation. And Unity also create a folder where it generates the material files based on the materials name we have in Blender. We have metal gold material and then we have the wood material. Unity nicely convert the color from blender material diffuse color to its material albedo color. Which is nice.

Setting up the animation

Lets go back to the parent folder. Now before we drag this object onto the scene view. We need to setup the animation first. So make sure it is selected in the project panel. Go to the inspector panel. Now, for simple animation like this we actually don’t need to use unity’s mecanim system. You can check at Unity’s official website to learn more about Mecanim. Basically in this tutorial I’m going to use the old or the legacy animation system. Mecanim is great but for simple animation like this, it can be an overkill. So to set our 3d model to use legacy animation system. We can go to the rig tab. In the “animation type” option, we can see it is defaulted to “generic”. If we click on this pull down list we can see that Unity actually support 3 systems: generic, legacy and humanoid. I believe both generic and humanoid use Mecanim system. So we should pick this “legacy” option up here. Click the apply button or otherwise the changes will not take affect. Okay, Now go to the animation tab. Notice currently we only have one animation or clip which is this “default take” as the name. Lets rename this first animation to “opening”. Then for this opening animation we want to assign blender’s animation from frame zero to frame 20. Again as we mentioned earlier 0 in here means 1 in blender and 20 in here means 21 in Blender. Next click this plus button to create the second clip. Rename it to “closing”. And for the closing animation we need to input 21 as the start frame and then 40 as the end frame. We can preview the animation down here. This is for closing animation. And this is for opening animation. Okay, so we have these 2 animations in here. Now these changes need to be applied by clicking this apply button. By clicking this apply button Unity will generate 2 animation clip files which are for opening and for closing. So lets hit apply in here. Now, notice, if we click this caret button in here. We have this hierarchical structure. We can see “body” object in here and then “cover” object. And down here we have the animation clips we have created before when we hit the apply button in the animation panel.

Now, we are ready to use this object in our scene. To put this into our scene simply click and drag this treasure chest object to the scene view like this. Okay, now that we have the object in the scene, notice that it is not placed exactly at the center. We can center this object by typing zero to these coordinate input fields one by one. But there is a faster way to do this and that will be clicking on this option panel which looks like a gear symbol. And then click on the “reset” option in here. As we can see now the object is visible in the center of the camera, because the camera is actually looking at the center of the 3D world by default. Okay now lets zoom out in the scene view to see our object and the camera. And lets move the treasure chest object so it is placed closer to the camera. Also lets move this a bit to the left so we can see the side of it. Okay, now we can see the whole treasure chest better.

Next we want to add interactivity to the chest object using a plugin or an editor extension asset called playmaker. Now I assume that you already purchase this asset as this is a paid asset not a free one. And that you already download it and install it in your project. If you correctly installed it, you will have playmaker menu up here and inside the menu, if you click on this “playmaker editor” you will have this window. Okay. Now because we want to add clicking behavior on this object, we need to add collider on it. So lets zoom in a bit in the scene view. We can press F to zoom extent a selected object. Now while the object is still selected go to the inspector panel and click “add component”. Type “box”, and unity will show several components that have ”box” word on it. Of course we don’t want the 2D collider as our object is a 3D object. So double click on this “box collider” component. Now you might notice that the box collider is not perfectly match the size of the chest object. We can edit the collider by clicking this button. We can see the faces of the box collider just like we see object in the edit mode inside blender. So we can grab this face and drag this up like this. Then this face down here to about this position. Another way to do this is by dragging this value. Oops sorry this is for the center position. It should be this one, the size, we can drag the x label in here to change the x dimension of the collider. Next we want to make our chest only detect collision or click events and not actually contributing to the physic simulation. To do that we can turn on this “is trigger” option in here. So again if this is turned on then if later a physic object fall onto this object, it will just pass through it like it doesn’t even exist. But if we set this “is trigger” off. When a physic object drop on it, it will stay there or bounce off. For now we turn on “is trigger” option as we don’t have any physic simulation going on in our scene and it is less taxing on the system performance this way.

Notice also on this object, unity already add this animation component for us which already include our 2 animation clips “opening” and “closing”. Now notice we have this “play automatically” option in here. If we have this turned on, when we hit the play button, it will play the opening animation as soon as the game start. Which is not what we want. So make sure this option is off. Okay after this is done. We can start adding interaction with playmaker.

As always don’t forget to subscribe to my channel. Give a thumbs-up if you like the video and give a thumbs-down if you don’t like the video. See you in the next part. Wassalamualaikum.

#unity #blender #tutorial #3Dmodeling #animation #playmaker

bottom of page