How can I make a hole in an object with Unity 3D? I've something like this object and I want to make a hole in it.
-
7\$\begingroup\$ Do you wish to make the hole in the editor or during gameplay? Unity does not have a built-in feature for the former, nor an easy function for the later. However, both can be achieved via code. \$\endgroup\$– MAndCommented Dec 28, 2015 at 17:37
-
2\$\begingroup\$ Do you want any old random hole in it or a distinct predefined hole at a specific location? \$\endgroup\$– StevenCommented Dec 28, 2015 at 21:29
5 Answers
You can't. Unity does not have CSG modeling options. You're going to either:
- construct your cylinder out of smaller parts
- model it in another program
- programmatically rebuild the mesh geometry at runtime. WARNING: ADVANCED TOPIC
-
\$\begingroup\$ In the advanced topic helm, there is also the option of coding a script to add that function to the editor. \$\endgroup\$– MAndCommented Dec 28, 2015 at 17:38
-
\$\begingroup\$ @MAnd true enough, and I've used one such tool. It was a pain in the arse to use (at least, the free version, which lacked a number of features). I'd categorize that as an "advanced topic" even within the advanced topic. \$\endgroup\$ Commented Dec 28, 2015 at 17:50
As of 2020, you can do this with ProBuilder's (experimental) Boolean CSG Tool.
- Install ProBuilder in Window > Package Manager.
- Enable Experimental Features in Edit > Preferences > ProBuilder.
- Select two PRoBuilder objects.
- Tools > ProBuilder > Experimental > Boolean
- Change Operation to Substraction (there's also Intersection and Union, BTW) and Apply.
A new object will be created. Works great with simple shapes so far:
-
\$\begingroup\$ This is no longer experimental. \$\endgroup\$– Evorlor ♦Commented Jul 5, 2023 at 12:19
Not directly. But there are several ways to achieve this:
Use a voxel engine. Then you can have objects that have some kind of "molecules". You can deform them in runtime.
Use a runtime mesh deformation plugin.
You may build your object in parts, and then attach them together in Unity, so you can create a hole by simply removing the part in the middle.
-
\$\begingroup\$ Both links appear to be dead. \$\endgroup\$ Commented Jul 5, 2022 at 16:14
-
1\$\begingroup\$ @THEJOATMON Updated the first link. The second link was a runtime mesh deformation plugin named
Meshinator - Realtime Mesh Deformation
, it is taken down from the Asset Store and I can't find it anywhere else at the moment, but there should be plenty of similar plugins in the Asset Store. Just search forRuntime Mesh Deformation
. \$\endgroup\$ Commented Jul 6, 2022 at 8:21
Maybe try Polybrush? Check out this tutorial right at 33:00 to see proof of concept. https://www.youtube.com/watch?v=GioRYdZbGGk
The woman in the video cuts custom shapes out of the plane. You can do it out of other objects too. Before you try it, make sure to install everything she tells you to in the beginning and learn how to insert an edge loop (basically a carved line) on your object at 10:05.
Personally for me, ProBuilder refused to work. I was able to load Pro Builder, but it wasn't showing my assets to add to the subtraction method. I'm using Unity 2020.1.14f1
For anyone who is wondering how to do this in 2023, you can use the package ProBuilder and use the subtraction tool to make a hole.