0
\$\begingroup\$

I'm making a plumber game, I have a pump prefab, and pipe section prefab, which allows the user to connect the pipe during game, the pipe needs to be connected seamlessly during game, which means pipe prefab needs to be aligned in pixel level, please check below enter image description here

User needs to add more and more pipe to connect the with each other, pipe is fixed length prefab.I've got choices,

1.Is the pipe prefab instantiated during game play a good practice? Because it might have many pipe prefabs, if the pipe goes a long way to another position, than there will needs to be so many pipe prefabs, compared to have procedrually generated pipe mesh during runtime, then a long pipe will not have to be cut off to the same small pieces?Which is good way to adpot?

2.If I use the same pipe prefabs to fabricate the piping system, how to accurately connect each other in pixel level, I can make the whole piping system in blender, then cut the system into pieces as my prefabs, then import to Unity as my first choice, this can do pixel level connection, but it seems to have better choice solely solved pixel level connection in Unity?

3.If I do it by generating the mesh during game play, then it could be complex especially it is hard to make elbow pipe mesh during runtime, or could you please advise me of some known library or package can do the work?

\$\endgroup\$
1
  • \$\begingroup\$ If you’re worried about performance, this sounds like the sort of thing that can be heavily optimized with GPU instancing. You don’t have that many distinct meshes, and they will be repeated a lot. Just make sure the material has GPU instancing enabled, and Unity should optimize it quite a bit. You can also look into combining meshes, but honestly I don’t think it would be necessary. \$\endgroup\$
    – Ed Marty
    Commented Jan 4, 2021 at 10:49

1 Answer 1

1
\$\begingroup\$

I think you are overthinking it. Usually this type of games have pipes that are taking 1x1 space, even if your visual representation looks like a 0.1x1 pipe, the player can normally rotate them, right? But never place them too close to each other, there is always a good space between them. So all you have to do now is snap your pipes to a grid since each piece has the same length and width.

I would not generate them on the fly but model a few pieces that you then use a prefabs. You need a corner, a straight, a t-crossing and a 4-way crossing. Maybe a deadend. Since you created them before, you can be sure that they are pixel perfect matching.

On your gameplay when the player drops a pipe, you check the x/y of the element and snap it to the next grid space, you overlap normally more than one place, you can pick the closer space by the difference in length between the center of your piece and the grid location center. It is always nice to give the player already the visual adjusted feedback where their tile is going to drop - like a shadow tile that gets displayed and the player knows immidiatly: if it stop dragging, my tile would be placed there.

Don't worry about the amount of prefabs, we are talking about how many? 100-200? That is nothing for a scene, even on mobile.

\$\endgroup\$
2
  • \$\begingroup\$ I will take the prefab approach ,the prefab amount might be thousands cause I am building a complex system, I will try that and check the performance \$\endgroup\$
    – Dew
    Commented Jan 4, 2021 at 10:40
  • \$\begingroup\$ even if you use thousands, you are not displaying all at once usually. I wouldnt worry about the performance until you actually run into performance issues. \$\endgroup\$
    – Zibelas
    Commented Jan 4, 2021 at 10:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .