Larger Scenes using SnapGroups

Make sure you’ve already done at least:

Demo: what we’re trying to achieve

In the video above, you see me:

  • A large set of pieces I previously snapped together
  • …automatically stored as a SnapGroup
  • We create 3 new pieces
  • …and snap them together, automatically creating a second SnapGroup
  • When we snap any piece in the 2nd group to a piece in the 1st group, the groups merge, and all pieces move at once

Let’s get started…

Building bigger scenes

Groups: the secret to large levels

Snapping pieces together is easy, as we’ve already seen. But this doesn’t scale well to large levels. What do you do once you have hundreds of prefabs, thousands of pieces in a single level?

Enter the SnapGroup: this groups-together pieces that have been snapped-together.

Creating a group

Is automatic! You’ve already created some in the previous tutorial.

Whenever you snap an object, a group is created for you, and SnapAndPlug intelligently re-centers the Group itself so that the center is approximately at the center of all the connected items.

Special rules with Groups

Snapping INSIDE Groups

You can snap piece-to-piece, group-to-group, and any combination of piece/group to each other.

But … you can also snap pieces INSIDE a group (this is very useful when you change your mind, or you’re trying out different positions for a new piece).

For more info, read the Advanced Snapping tutorial

Groups as Prefabs

Ideally, you’d make all your SnapPieces into prefabs, and then group sets of them together into SnapGroups, and make those prefabs too.

Unity’s support for “prefabs inside prefabs” is improving, but isn’t perfect. If you try this, I can’t guarantee it will work. For now, I recommend disconnecting your prefab instances for all the SnapPiece objects before converting your SnapGroup into a new prefab.

Problems?

With Groups, a single snap operation is doing a LOT of work behind the scenes. I’ve tested extensively, but there may still be problems.

If anything goes wrong, please get in touch via the Unity3D support forum: http://forum.unity3d.com/threads/wip-snap-and-plug-join-anything-to-anything.268490/

Other tutorials