Mesh Collision from Blender into unity. Easy way.
Вставка
- Опубліковано 19 сер 2024
- A method to use collision mesh from Blender in Unity in a quite efficient way. No beed to add zillions of Box Colliders by urself in Unity. You can do it in Blender, that is a better tool for managing such task.
music :
Title: Midnight Stroll
Artist: Ghostrifter Official
Genre: Jazz & Blues
Mood: Calm
Download: bit.ly/2CzM9fy
thank you so much. it is kind of ironic tho when you said "unity doesn't have one at the moment" XD. even unreal engine 3 had a prefix system lol. 2024 still no sign of it, but glad there is this option to add a mesh collider and pick a custom mesh.
This is a rare finding. I needed this before but couldn't find it. I will try this now and will let you know. Thank you!
THANK YOU SO MUCH!!!!!!!!!!!!!!!!!!! I have been looking for a free solve to the same problem for days now. You are a life saver.
+1 like +1 subscribe and rung the bell.
Happy it helps! I post in general issue that I really had difficulties to find in some other videos!
6:23 "AND VOILA !!!"
Merci en tous cas pour le tuto Eric 😂😂 J'espère que ça fonctionne encore sur les versions plus récentes (même s'il n'y a pas de raisons).
Not only informative but also has good music.
You sir, deserve more subscribers!
thank you!
Nice thanks! Good to know the need to group all boxes of a model to a plane to bind them together for Unity.
Hello Mohamed, thanks. You do not have to do it, you can do it manually in Unity ... but the target is indeed to make the less of work in Unity
Thank you for the tutorial, was wondering how to handle complex meshes with multiple colliders.
glad it helped ! :) I may do a another video with a more complex shape, such a spaceship and an FPS controller with rigidbody
This is good!
glad it helped!
Thats why unreal engine is so superior in functionality. It has built in collision hull and vertex accuracy in the object editor. Doing physics thing easily in unity is a real pain in the ass
Nb: I am a unity user.
Nice tutorial, thank you!
Would be great if you made a part 2 where you would explain how to deal with hollow objects. :)
Thx. yes I think I can do an example with a spaceship or something like that.
@@MrEricGuerin did u do it ?
not a bad workaround. Pretty clever
this helped me a lot! thanks!
this is the best way, thank you
thank you and have a nice day :)
Great Video man
thanks !
A very usefull workaround. thx a lot
Very useful, thank you very much!!
The music that has lyrics is distracting. Thank you though.
yes - sorry first tutorial - made it quickly so ... :-/
Awesome!!!
The voices in your background track are interfering with the ability to distinguish your voice.
yeah .. I can admit that the choice of this music track as a background song was not optimal.
However if you have a question, I'll glad to help
very usefull thank you
the next question I will ask I have not found a satisfactory answer
Note: I had already gone through this discovery on my own, I know that it limited the problem in a limited way.
Question:
put one more property and add one more collision box to the mesh, what does it cost in engine performance? How much is this encouraged when you have (I will take as an example the chair with which you are doing the example) a chair that has to put collisions on the legs, seat, and backrest, on average this would be 6 collision boxes, ([1 on each leg = 4 collision boxes] + [1 on the seat = 1 + 1 collision box] + [1 on the backrest = 1 + 1 collision box] = 6 COLLISION BOXES, but I don't know what cost has this in consumption of resources of my computer or in the game engine.
Can you explain this to me? It is encouraged, it becomes heavy, is it too many calculations? what about performance?
you kind of answer it yourself Mauricio.An absolute rule is to make things faster and simple enough for making your world where the player is playing realistic enough to be credible.
But of course, to do so in a huge environment, you may run in performance issue as soon as you simulate with an exact physic simulation *all the elements* of our scene.
For example, if in your game, the fact to have a chair with 4 legs, a back plus the place to seat need to be simulated, because you need it in your gameplay, then do it. Now if it s only for the decoration, don't (or two boxes can be enough maybe.)
The problem of performance is a huge pb in video games : not everybody has the same machine, and even now, it s 'worse' because you could have a game also running on older consoles, or some mobiles, where the power of calculation graphic cards, have a huge difference in technology support (shaders version) .
So everything is depending of the target machines for your game, the game play, the complexity of your scene, so it s only you that can decide where things need maybe simplification.
That's why you will need also testers with a huge variety of machines to see how your game is running.
Better to have a game running at 30 fps with a more approx physics, but still looking good, than 5fps with a perfect physic.
What you want is first that people play your game AND have fun. That's your main goal. Never mind if sometimes you will need to do some compromise.
A good example of that, is for example boat floating on the sea.
ua-cam.com/video/aGUh41wNiss/v-deo.html look at my video (no sound) it s *not real physic* applied of the model of the ship, however it follows the shape of the waves and from a player point of view is fair enough.
So, only you can decide where to put machine resources to simulate things.
but mesh collider will be heavier on performance
it is true, however, like everything, colliders need to be put in a smart way and so, in a smart quantities. Put them where it matters.
Like in this example, with a diagonal colliders, better to do it that way. In any case, as a developer you need also to do 'smart' decisions all the time - so the question you need to ask yourself all the time is : 'does it worth it? is it pertinent to do it? is it performant enough?'
But again, performance come LAST in game dev - first it s better to have a 'slower' game than a performant game that ... never come out. Moreover, every 6 months hardware gets more and more powerful - so some issues that are relevant today will not really be an issue where your game is released. Hope it helps !
I couldn't understand anything. I look for concave mesh....
anything like ? I can help you, but be more specific. Concave meshes do not work with Unity ... UNLESS it is not a moving shape. Here it is about shapes that use physics (like gravity) and that do not use the approximative convex shape calculated via unity - because it s too aproximate, like this example with the chair or the stairs.
You need to do some manipulation like I show in the video.
@@MrEricGuerin I understand what do you mean but I have a object like a tube and I can't convert it to basic shapes, it is not working. I don't know how i will detect collision enter without rigidbody or with concave mesh. Sorry for my English also
@@erenenadream a tube? Does it mean you want to enter the tube ? Or it s just a full filled tube where nothing can go in?
If it s the last one, you can let Unity to create a convex shape of it. Now if you want to be 'inside' the tube, like a corridor of a moving space ship, you need to create a simple approximation of this shape tube with rectangles, 6 or more for example but not too many, in that way the physic engine will consider this simple collection of convex shapes as the collider of your tunnel shape (that looks concave).
Do you understand?
@@MrEricGuerin Thank you! I did with rectangles and now it is working well, i liked your video.
@@erenenadream you are welcome! :)
Thanks 👍👍👍👍
This is okay for prototyping but doesnt work in release, because it isnt performant at all.
In release you will want to combine all separate meshes into 1 single large mesh as much as possible, because for every mesh = 1 material and atleast 4-8 draw calls, if you split your mesh into a 10 parts it will be 40-80 draw calls per frame, but thats just with 1 material, if you have 2 materials or some triplanar it will easily be 200 draw calls per mesh per frame lol.
Well 'define' not performant/not working in release.
It does.
This method is not to be used on a full static scene. it s only for some MOVING (non static) objects that needs to still interact with physics.
As you see in the example, the stairs falls before, got also a falling ball interacting with it.
Now you are right on one point; you can merge into a huge object all the same objects that are ... statics+one material. It will reduce the nb of draw calls, but nothing is magic: if you need to do some stuff(physics, script, etc), you may impact your perf in other hand.
Nothing will beat a pure static one object scene in terme of speed ;-)
@@MrEricGuerin Yes you are right its a cool trick that can be useful in some situations, I am working on a big game in particular and also have these convex collider issues, but this is not a solution for us, which is why I said those things in my comment.
Really Unity should fix a lot of things, they like to add new features every year, but everything they add is never finished, its always very basic, which is in my opinion the biggest drawback of Unity. The real solution to this problem is by Unity fixing their colliders lol.
Hey what if my mesh is like a sphere, which is hollow from the inside, (I wanna make objects bounce around inside the sphere), how do I create a convex mesh for that sphere?
Do you want the hollow shpere moving with Physics too ?
if not, then use the mesh collider of Uniy.
If the answer is yes, then you are in the worse case scenario. You will need to approximate the inner shpere collider in a mutiple shapes that can be good enough to represent the sphere (an convex!) that may be tedious and not funny ...
However if you want an exact bouncing it may be too costy in shapes.
I wld recommand more for a script that emulates that : ie: adding a sphere trigger collider that represents your inner hollow sphere border, then creat a script that detects when objects exist the sphere trigger, you can apply an opposite force to push them back to the center of the sphere ... that's my first idea. It should be fast and efficient.
Hope it helps !
@@MrEricGuerin well the answer is yes, and it rly is worse than the worst case scenario😅 I even have to simulate water in the sphere, well I will try adding a hemisphere woth some kind of shader to make it look like water I guess, anyway thanks for help man rly appreciate it!
What do if you mesh its circle?
can you tell me more about what you want to do ?
I have 3D models I imported from Blender for an endless runner I’m making, and when I attempt to Add Component > Box Collider, it spawns a box below the object. I cannot find an answer anywhere as to why the Box Collider doesn’t just outline the object like it should.
I can edit the collider, sure. But that shouldn’t be necessary. Why doesn’t my box collider auto detect the shape of the object? Almost as if my object isn’t even there...
is it possible that your imported 3D object is made of different meshes and you tried to add the box collider on the gameobject itself ? (so if you prefer, you add a box collider on the PARENT object of the mesh, and not the mesh object itself ?
It's also strange to me, why did you add the box collider to your stairs? You already have a nice mesh that is responsible for the correct collision - why do you need any additional remedy?
it is indeed (in 2020) not an need anymore to do so. I should remake a video up to date.
You need indeed to put collision meshes (check convex) for all the part of your mesh, and if you have a game object that is the parent of the 3D object (I think it was the case if in the video), you can just add the rigidbody only, no need to add an extra box collider. Thanks for your remark - it will help those who are following the tuto (and reading) the comments ! :)
@@MrEricGuerin In 2020 is this process still required, or does unity handle mesh collisions differently? Do I still need to model separate collision meshes in blender?
@@NethanielShade Unity will not do that for you ATM. if you have a 'complex' moving collision meshes, you need to make them in Blender (a list of different CONVEX meshes that will be used for Unity as colliders), like in the video. PLEASE also do not mix with the auto collider generation system provided by Unity, that works, but ONLY for NONE MOVING objects. It is important, in this video, it's about handeling collision objects for movable objects by Physics.
Otherwise, yes, if it s a rock or a building that will never move, you can use the mesh collider directly generated by Unity. Hope it helps!
neat... but i not get exactly how you get a other mesh layer in blender... may a longer tutorial you can evolve the explanation, i a bit raw in blender and want this kind of stuff, but not know enought to understand what you do in blender... i already create some mesh, but not work with multiply layers or anything that advanced hehe... well i will do somes tries
thanks anyway!
Hello thanks for your comment. What you mean by "layer", in Blender is 'Object', right?
then, if your model is complex (=several objects for one 3D model) you need to create enough several convex objects in Blender that will represent your collider in Unity.
A "collider" in Blender is just an object (so made of vertices like the one made for your "visual" mesh) the only diff is that you will not show the mesh part dedicated for the collision on screen.
So imagine you have a complex 3D model in Blender made of a 2 cubes (=1 object (or layer?)) and a pyramide (made of 1 object) => you need to create 3 other objects : 2 cubes and 1 pyramide that will represent you collision mesh.
But maybe it could worse I create a new updated tutorial, with a step by step for Unity and Blender 2.8.
is it at all possible to do this with using just blender?
well it depends about what you mean by 'all' . But otherwise yes, it s what you see in the video
DELETEING THE MESH RENDER WILL MAKE THE OBJECT DISAPEAR
no, you delete the mesh renderer of the COLLISION OBJECT ONLY - not the rendering of the object itself.
If you want, you have 2 shapes with 2 renderers - one is used to represent visually your Gameobject for example a car (with the wheels etc), and the other is a convex shape for the collider - it s this one you delete. And ship shape you design on Blender can be just the simplified shape of the hull of the car.
Got it ?
How I add a collider to a home or tunnel in blender ,please
You will need to make SEVERAL objects, with several simplified colliders, like in the example in the video(the mesh that look like a stair). For example for ur home, you will need 4 colliders for the 4 walls, 1 for the floor, 1 for the floor etc ...
Jesus Christ loves yall if yall did not know come to Christ repent non denominational King James Version John 3:16-17 16 For God so loved the world, that he gave his only begotten Son, that whosoever believeth in him should not perish, but have everlasting life. 17 For God sent not his Son into the world to condemn the world; but that the world through him might be saved.
King James Version James 4:8 “Draw nigh to God, and he will draw nigh to you. Cleanse your hands, ye sinners; and purify your hearts, ye double minded.”
Hmmm is there a similar method for procedurally generated mesh?
if it s a proc mesh, you need to add a mesh collider component, like so
mesh = new Mesh ();
...
.... (set the indexes & vertices into your generated mesh)
...
MeshCollider meshCollider = gameObject.AddComponent ();
meshCollider.sharedMesh = mesh;
Now, you need to be sure the mesh you create is a convex mesh if you need a dynamic (moving) object reactinfg to Physics. If it s a static object (like a generation of ground or building) you do not have this restriction.
@@MrEricGuerin my mesh is non convex and need physics... I have no idea how I could split my mesh into convex mesh collider since its procedural...
@@nukee2283 if it s fine in your scenario, you can still force to calculate a convex form for your collision from the collision mesh you created by doing :
meshCollider.convex = true;
Otherwise, split it in different parts, if you know exactly what kind of type of part of your procedural mesh you are generated.
For example, if you have a car, do not generate fully the car, but generate separatly the door, the windshield etc ... if the full approixamte convex shape is not good for you.
May I ask you what kind of model are you trying to generate?
can you please tell what if the mesh is not fit to the object ??? how to fix that?
Hi Danane, can you explain me a bit more your issue? What do you mean by 'if the mesh is not fit to the object'?
@@MrEricGuerin the mesh of my chracter is not fit to it ? when i add mesh collider and drag the mesh of my character it looks just like this answers.unity.com/storage/temp/27471-2.jpg
@@codemoor what I can see on your picture, it s that you split the rendition of your mesh (so the mesh what you see in game) and the collider mesh into 2 diff objects (in the same hierachy, however, still not the same gameobject) - maybe the one where you put the camera and the rendition mesh are a little off on the Y axis from the parent one, so that's maybe why you have the issue.
@ABD JALIL Danane did it solve your issue ?
What do you do when your mesh collider is taking the mesh of a model that doesn't exist? I was walking into walls that don't exist anymore in Unity because I deleted them all and I even double checked the meshes were the correct ones and they definitely are. I've also tried reimporting the model but that didn't work either. Any ideas?
hum. Not really sure about ur pb 'taking a mesh that does not exist'.
My advice would be to delete this gameobject and restart from scratch.
but, the idea is that if you remove ONLY a renderer only (a component that appears on the right of the unity editor and you select a gameobject) then your object DOES NOT RENDER - however the collisions, or scripts attached to this gameobject will be still active.
I will need more to understand your pb - maybe a screen shot, a video or a zip of your project ?
how do you export the objects properly?
sorry _ I jusr see your question now - if your question is still valid (more likely not I guess after one year) I can help you
How to do it in Blender 2.8?
well pretty much the same. If you want I can do a quick video updated about it, but it s fairly close in term of process.
this isn't easy way, why would I waste time on every model I make and add colliders..
well it depends on the purpose : if you DO NOT need a MOVING RIGIDBODY it s not necessary - just use the mesh collider from Unity.
Here, it s a about a specific case. Now, you could just use a sphere or a box colliders (provided by unity), and it s maybe again enough in your scenario.
However, the fact to use the mesh editor of your choice - here Blender - is a life(time) saver.
Eric GUERIN Thank you, you explained very well.
Is this good for mobile game's too 3d?
for sure!The main difference between desktop and mobile is the number of vertices (polygons) of your mesh / collider.
The lower the best.
@@MrEricGuerin ok thank you ✨✨👍
Hey, You sound French are you?
2:27 min what you did here to put a plane in the form of a slope, it already seems to me crap if it is a professional point of view, because your physics are already wrong from the moment you apply a solution as mediocre as putting a plane tilted, the sphere will not bounce as it should the physics will cause an inadequate and erroneous reaction to the one produced by a ladder, and if your event that is about to happen should stick to the physics that you are applying, because you are already preparing so that it does not get a proper result
well, if your remark is about a stair with a stair collider shape that should be for each steps of the stair, yes, of course you can. Maybe the video is not clear enough, but is basically how to make any complex mesh so with concave shapes, and movable by Physics. Now the complexity of your collider is up to you, if it s relevant to your game play, the target machines (PS or Mobiles for example)
The method here is to show you how to accomplish it in a simple way. (by not using the collider build in Unity that are too simple for most realistic game cases)
Maybe a better example should have been a moving car or a spaceship where a player can enter into it, and the ship or the car can be still movable by Physics.
So about the stair mesh itself, of course, in Blender, nothing forbid you to have a more closer shape that represents each steps of the mesh (stair). The idea here was about to make collider in Blender (and not Unity) and use them as collider for Physics. You can of course do a better quality collider mesh (depend on your game scenario, but keep in mind they need to be fairly simple (performance issue if your machine is slow) an convex (not concave) ... but, yes, if you want to push the physic in a more realistic way for some specific part of your model, you are free to do it and this method is still valid. I hope it clarify your remark.
.
@@MrEricGuerin understand , thanks, yes is clear
i dont understand you
What do you not understand ? (do not tell me all ... because I have a french accent)
its not your accent its like confusing what are you doing in the video
Ton accent français mdrrr
Can't hear anything. This is more frustrating than listening to tutorials made by indians. :)
my advice : turn on your speakers ;-)
That happens when u start playing an video for like one second then stop it and comment. The Voice in the Beginning is the Background Ambience lul
@@Incenpilz ok next time I will put an elevator song without lyrics :-)
@@MrEricGuerin I don't think that's necessary xD Good video btw