Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

dragging Blender objects into the scene

Discussion in 'Asset Importing & Exporting' started by FrankBuss, Dec 22, 2014.

  1. FrankBuss

    FrankBuss

    Joined:
    Dec 22, 2014
    Posts:
    55
    I'm new to Unity and I created a Blender file with two objects (Ball and Box). I can import this into Unity and I see both objects in the Assets list (when I click on the arrow at "test"), each one twice, one time with material and one time without material. But when I drag an object with material (Ball) into the scene, both objects are in the scene, see attached file. I can then delete the other object, but not a good idea if I would have a Blender file with dozens of objects.

    Strange side note: When I use a script and the Instantiate function to create the Ball, just the Ball is created, not the Box.

    Any idea if I'm doing something wrong?
     

    Attached Files:

  2. FrankBuss

    FrankBuss

    Joined:
    Dec 22, 2014
    Posts:
    55
    Ok, I found some workaround: First I drag the "assets" symbol into the Hierarchy panel, then I open the tree and drag the individual objects back into the Assets panel. Then I can delete the assets symbol in the Hierarchy panel and drag the individual assets into the scene and then there is only one object drawn.
     
  3. kburkhart84

    kburkhart84

    Joined:
    Apr 28, 2012
    Posts:
    910
    That exactly right there is your problem. You shouldn't be having more than one object in a Blender file. If you were to be exporting them to separate FBX files, it wouldn't matter. But since you are using it as a blend and letting Unity do the export, it assumes that it is a single object. Just make two separate blend files, or export them to fbx yourself and you won't have to have that workaround. One exception to this would be if the separate objects should be parts of a single object, like separate parts of a tank or something.

    The one time I kept more than 1 object in a file recently was when I wanted a good variety of asteroids for my Ludum Dare game. I had a single object that was the actual asteroid, which contained the mesh renderer, controller scripts, etc... The controller(or a separate script I think actually) had a public variable in the inspector which was just an array of meshes(which then has a random one of them chosen in the script). All of those meshes came from the same blend file, and are "stuck together" just like they are as you mention above. But since I'm not putting this thing directly into the hierarchy, rather just using the individual meshes in another object, the issue you complain about doesn't affect me here. But for pretty much anything else, I always keep my meshes separate.

    Another thing I should mention, you maybe shouldn't worry too much about size, as long as you are close. If you are trying to keep things in the same file in order to match sizes, don't. You can always scale things in the Unity editor. They say you shouldn't scale the top-level gameObject if possible(something about physics or something, I'm not sure), but that doesn't apply to children objects I don't think. So, you can just have a second gameObject as a child of the primary, with the meshRenderer on that object, rotated and scaled as needed in case it isn't right from Blender. Then you simply do everything else on the parent object and it works great.
     
  4. FrankBuss

    FrankBuss

    Joined:
    Dec 22, 2014
    Posts:
    55
    I'm not an artist, but I think it is not a good idea to use individual Blender files for each object, because it is easier if you can edit multiple objects of the same kind (like your astroids, but think of characters which should all have the same style) at the same time, without the need to start Blender multiple times, or switch files often, or chaning the size of every object in Unity manually.

    But I think it is a bug anyway, not a feature, if it is not my fault how to use the user interface or some hidden setting. And it is not consistent with scripting: If I define a public variable of type Transform, then drag one object from the assets list of the one Blender file to the variable in the inspector, and then use "Instantiate(myObject, new Vector3(0, 0, 0), Quaternion.identity)" to create an instance, I get only one object, not all like when I drag the same object into the scene.
     
  5. kburkhart84

    kburkhart84

    Joined:
    Apr 28, 2012
    Posts:
    910
    I'm not really an artist either, though I have a bit of technical knowledge. You may consider it a bug, though I think Unity's team did it on purpose. See, the "object" that is at the top of the hierarchy is basically what is created out of the blend file, which includes all the meshes in said file. While the individual "objects" you are dragging are really just the "meshes." Unless I'm misunderstanding it, Unity is creating a sort of default object with just that mesh when you use Instantiate with it. The normal use of Instantiate is with prefabs, not meshes, so I'm not fully sure how that is working in the first place. The reason it works for my asteroids is because I'm intentionally using the meshes as meshes, not as their own objects.

    What I'm wondering is what you are going to do when you start using things with animations, maybe blendshapes, etc... I'm not sure that will work in your current pipeline.

    But, I have the solution for you if you really want to keep things in the same blend file. In fact, I can see your logic in wanting to do so too. The best way to do this is to export the FBX files yourself from Blender into Unity's asset folders. Keep the actual blend file outside of the project structure and just export the FBX yourself. Then, you can select whichever mesh you want to export to the FBX regardless of how many things you actually have in that single blend file. You will also avoid the issue that you are calling a bug, but at least in the Unity editor, you will still have multiple asset files(objects as you are calling them), but you get to keep things in your single blend file this way. The catch is that you can lose some of the automagicness(love my word there) that is Unity importing changes automatically since you now have to do the export yourself, which Unity would then pick up as changed and re-import.

    My other recommendation is that you quit dragging the meshes onto Transform variables. It may work, but unless I'm mistaken it isn't really what you want to be doing, and if I'm right about it not really being documented, it could later have changes made making it now work, or only work in certain situations. I've been wrong before so you could ask in another topic for details about that. The "normal" way is to create prefabs. Remember that prefabs can include much more than just the mesh, including anything you can attach to a gameObject, including any child gameObjects, and all components included, like colliders, rigidbodies, any renderers like particles, line and trail renderers, and any scripts you are using. If you are just dragging the meshes around you lose the advantages prefabs can provide.
     
  6. scarybloke

    scarybloke

    Joined:
    Sep 21, 2015
    Posts:
    1
    i cant get my drag my blender files onto the scene, any ideas?