HomeSystem plugins › AFS_Core_Snapping
System

AFS_Core_Snapping

Connector and anchor components with matrix-based snap transforms, surface alignment from a hit normal, anchor caching and ghost previews.

What it gives you

  • Objects that snap into defined slots
  • Surface snapping aligned to any hit normal
  • Keyed connections through connector IDs
  • Ghost preview while searching

Requires

AFM_Abilities AFM_AutoDestroy AFM_MeshCopy

Required by

AFE_Showroom AFS_UISpace_Hand AFS_UX_Grip AF_Examples

9 assets61 API members

Description

Snapping is expressed as a pair. A connector lives on the movable object and searches; an anchor lives on the target and accepts. The connector computes the transform that places itself exactly on the anchor, so the object arrives correctly oriented regardless of where it was grabbed.

BPC_Connector_Anchor matches against anchors by ID, which is how you build keyed connections — a battery that only fits its own slot. BPC_Connector_Surface instead traces for a surface and aligns to the hit normal, which is how you place objects on arbitrary walls and tables.

An anchor cache on the game state means connectors find candidates by ID lookup rather than by searching the level every frame.

Setup

  1. Enable AFS_Core_Snapping. Its Engine.ini enables Custom Depth-Stencil.
  2. On the movable object, add BPC_Connector_Anchor or BPC_Connector_Surface and position it where the object should meet the target.
  3. On the target, add BPC_Anchor and position it.
  4. Set Connector ID on the connector and add it to the anchor's Connector IDs To Allow.
A connector on the object and an anchor on the target
AFS_Core_Snapping_setup.pngA connector on the object and an anchor on the target
A connector on the object and an anchor on the target

Usage

Keyed connections

Give the connector a Connector ID and list it in the anchor's allow list. Leave the allow list empty to accept anything.

Surface placement

Use BPC_Connector_Surface and set Rotate On Surface to control whether the object keeps its rotation or aligns to the normal.

Previewing

Turn on Show Snapping Preview for a ghost of the snapped result while the object is held, and Show Anchors On Search to reveal compatible anchors.

The battery held beside its slot, snap preview showing where it will land
AFS_Core_Snapping_result.pngThe battery held beside its slot, snap preview showing where it will land
The battery held beside its slot, snap preview showing where it will land

Key properties

PropertyWhen to change
Search DistanceHow near the object must be before a destination is offered
Release TypeWhether releasing snaps and attaches, snaps only, or does nothing
Connector IDs To AllowTo key an anchor to specific connectors
Rotate On SurfaceSurface connectors: keep rotation, align to normal, or align and face player
Wall Rotation AdjustmentWhen the object's forward axis is not its natural facing

Extending

Derive from BPC_Connector and override searchForAcceptableDestination and getDesiredRelativeTransform for a new snapping rule.

Multiplayer notes

Multiplayer

Attachment replicates through Server_AttachConnectorToComponent and its detach counterpart, so every client sees the same connection.

Example map

Map_Examples_Snapping shows keyed anchor snapping with a battery and lightbulb, plus surface snapping.

Troubleshooting

Nothing snaps. The connector ID is not in the anchor's allow list, or Search Distance is shorter than the gap.

The object arrives rotated wrongly. Adjust Wall Rotation Adjustment, or reposition the connector so its axes match the anchor's.

API reference

Every blueprint asset in this plugin. Expand an asset to see its members.

Components

BPC_Anchor13 members
extends SceneComponent
KindNameSignatureDescription
varConnectorIDsToAllowSettingsname[]Connector IDs this anchor accepts. Leave empty to accept any connector; fill it in to build keyed connections such as a battery that only fits its own slot.
varConnectorShouldAttachSettingsboolWhether a connector physically attaches to this anchor, or merely snaps its transform without parenting.
varSphereRadiusSettingsfloatRadius within which a searching connector will consider this anchor.
fnDrawDebugSettings()Draws the anchor's search sphere in the world, for tuning placement.
fnIsConnectorAllowedState(AnchorConnector: BPC_Connector_Anchor, out Allowed: bool)Returns whether the given connector is permitted by this anchor's allow list.
fngetAnchorCacheCache() → BPC_AnchorCacheReturns the game-state anchor cache used to look anchors up by ID without searching the level.
fnIsAvailableState() → boolReturns whether this anchor is currently free, meaning nothing is already attached to it.
eventSetOccupyAnchor(Set: bool)Marks the anchor as occupied or free, so other connectors skip it while it is in use.
eventSetAttachedConnector(Connector: BPC_Connector_Anchor, Set: bool)Records or clears the connector currently attached to this anchor.
eventConnectorSetSearching(Set: bool, ConnectorAnchor: BPC_Connector_Anchor)Called when a connector starts or stops searching, so the anchor can show or hide its preview.
eventCorrectListOfHelpers()Reconciles the anchor's preview helper actors with the connectors currently searching.
eventAnchorHovered(ConnectorAnchor: BPC_Connector_Anchor)Called when a searching connector selects this anchor as its current best candidate, so it can highlight.
eventOnDestroyed_Event(DestroyedActor: Actor)Internal handler that removes this anchor from the cache when its owner is destroyed.
BPC_Connector20 members
extends SceneComponent
KindNameSignatureDescription
varReleaseTypeSettingsE_Snap_AttachTypeWhat happens when the object is released near a valid destination: snap and attach, snap only, or nothing.
varSearchDistanceSettingsfloatHow far the connector looks for a valid destination while being carried.
varShowSnappingPreviewPreviewboolWhether a ghost preview of the snapped result is shown while searching.
varSoundLocationFoundSoundSoundBaseSound played when a valid snap destination is first found.
varSoundLocationLostSoundSoundBaseSound played when the connector loses its snap destination.
varSound_DetachSoundSoundBaseSound played when the connector detaches from a destination.
varSound_AttachSoundSoundBaseSound played when the connector attaches to a destination.
fngetDesiredRelativeTransformTransform() → TransformReturns the transform the owning actor should take relative to the destination. Override in a subclass to change how the object aligns.
fnsearchForAcceptableDestinationTrace(out ComponentToAttachTo: SceneComponent, out DesiredDestination: Transform, out Priority: float, out SocketToAttachTo: name)Looks for the best snap destination within search distance and returns it with a priority score. Override to implement a new snapping rule.
fngetAllActorsToIgnoreTrace(out ActorsToIgnore: Actor[])Returns actors excluded from the destination search, normally the carried object and the player.
fngetAnchorCache() → BPC_AnchorCacheReturns the anchor cache held on the game state, adding it the first time it is asked for. Every connector shares that one cache, which is how a connector finds candidate anchors without searching the level.
fngetSnapTransformTransform(InConnector: BPC_Connector, InWorldAnchorTransform: Transform, out OutWorldSnapTransform: Transform)Computes the world transform that places this connector exactly on the given anchor transform.
fngetAnchorTransformTransform(InConnector: BPC_Connector, InAnchor: BPC_Anchor, out OutWorldSnapTransform: Transform)Computes the world transform that places this connector on the given anchor component.
eventAttachConnectorToComponent(Transform: Transform, Component: SceneComponent, SocketName: name)Attaches the owning actor to the target component at the given transform and socket.
eventDetachConnectorFromActor()Detaches the owning actor from whatever it is currently snapped to.
eventPositionToRelativeTransform(Transform: Transform, TargetSceneComponent: SceneComponent, TargetSocket: name, UseMotion: bool)Moves the owning actor to the given relative transform, optionally animating the movement rather than snapping instantly.
eventServer_AttachConnectorToComponent(RelativeTransform: Transform, Component: SceneComponent, SocketName: name)Replicated attach, so every client sees the object snapped to the same destination.
eventServer_DetachConnectorFromActor()Clears this connector's stored connection on the server, which replicates the break out to every client. Called by Detach Connector From Actor; the detach sound is played locally by the caller, so calling this on its own breaks the link silently.
eventConnectorFoundDesiredLocation(Transform: Transform, ComponentToAttachTo: SceneComponent)Fires when a valid destination is found, carrying the transform and target component. Bind to it to drive custom preview visuals.
eventSetSearch(Search: bool)Starts or stops searching for a destination. Normally driven by the grip system when the object is picked up and released.
BPC_Connector_Anchor9 members
extends BPC_Connector
KindNameSignatureDescription
varConnectorIDSettingsnameIdentifier matched against an anchor's allow list. Use it to make a connector fit only certain anchors.
varShowAnchorsOnSearchAnchorsboolWhether compatible anchors reveal themselves while this connector is searching, so the player can see where the object fits.
fnsearchForAcceptableDestination(out ComponentToAttachTo: SceneComponent, out DesiredDestination: Transform, out Priority: float, out SocketToAttachTo: name)Searches the anchor cache for the closest compatible anchor within search distance.
eventOnConnectorAttached_Event(Connector: BPC_Connector, AttachedToComponent: SceneComponent)Internal handler that marks the target anchor occupied once attachment completes.
eventOnConnectorDetached_Event(Connector: BPC_Connector, DetachedFromComponent: SceneComponent)Internal handler that frees the anchor when the connector detaches.
eventPositionToRelativeTransform(Transform: Transform, TargetSceneComponent: SceneComponent, TargetSocket: name, UseMotion: bool)Moves the owner onto the anchor, animating when requested.
eventAttachConnectorToAnchor(Anchor: BPC_Anchor)Attaches this connector to a specific anchor, bypassing the search.
eventConnectorFoundDesiredLocation(Transform: Transform, ComponentToAttachTo: SceneComponent)Fires when a compatible anchor is found.
eventSetSearch(Search: bool)Starts or stops the anchor search, revealing compatible anchors when configured to.
BPC_Connector_Surface7 members
extends BPC_Connector
KindNameSignatureDescription
varRotateOnSurfaceSettingsE_Snapping_RotateHow the object orients once placed on a surface: keep its rotation, align to the surface normal, or align and face the player.
varRequiresTagSettingsnameActor tag a surface must carry to accept this connector. Leave empty to allow any surface.
varWallRotationAdjustmentSettingsfloatExtra yaw applied when snapping to a vertical surface, for objects whose forward axis is not the natural facing direction.
fnsearchForAcceptableDestination(out ComponentToAttachTo: SceneComponent, out DesiredDestination: Transform, out Priority: float, out SocketToAttachTo: name)Traces for a surface within search distance and returns the snap transform aligned to its normal.
fngetDesiredRelativeTransform() → TransformReturns the transform placing the owner flat against the found surface.
fngetSurfaceTransformTransform(InConnectorSurface: BPC_Connector_Surface, InHitPoint: Vector, InNormal: Vector, out OutTransform: Transform)Computes the world transform that seats this connector on a surface at the given hit point and normal.
fnalignRotationToNormalTransform(InNormal: Vector, InRotation: Rotator, out OutRotation: Rotator)Rotates a rotator so its up axis matches the given surface normal while preserving its facing as closely as possible.

Helper

BPC_AnchorCache4 members
extends ActorComponent
KindNameSignatureDescription
fnAddAnchorToCacheCache(ID: name, Anchor: BPC_Anchor)Registers an anchor under an ID so connectors can find it without searching the level.
fnRemoveAnchorFromCacheCache(ID: name, Anchor: BPC_Anchor)Takes an anchor out of the list registered under the given identifier, so connectors stop offering it as a snap target. Anchors call this themselves when they are deactivated or destroyed.
fngetAllAnchorsForIDCache(ref const ID: name, out Anchors: BPC_Anchor[])Returns every cached anchor registered under the given ID.
fngetSnapLocationHelperSnap Helper() → BP_Helper_SnapLocationReturns the shared helper actor used to visualise snap locations.
BP_Helper_MeshCopy_Anchor4 members
extends BP_Helper_MeshCopy
KindNameSignatureDescription
varSphereRadiusSettingsfloatRadius of the anchor indicator sphere.
varAnchorBPC_AnchorThe anchor this preview represents.
varColor_HoveredStyleLinearColorColour used when this anchor is the connector's current best candidate.
eventAnchorHovered()Switches the preview to its hovered colour.
BP_Helper_MeshCopy_Preview0 members
extends BP_Helper_MeshCopy

No editor-visible members; this asset configures defaults only.

BP_Helper_SnapLocation0 members
extends Actor

No editor-visible members; this asset configures defaults only.

Libraries

FL_Snapping4 members
extends BlueprintFunctionLibrary
KindNameSignatureDescription
fnGetSnapTransform(InConnector: BPC_Connector, InWorldAnchorTransform: Transform, __WorldContext: Object, out OutTransform: Transform)Returns the world transform that places a connector exactly on the given anchor transform.
fnGetSurfaceTransform(InConnectorSurface: BPC_Connector_Surface, InNormal: Vector, InHitPoint: Vector, __WorldContext: Object, out OutTransform: Transform)Returns the world transform that seats a surface connector on a surface at the given hit point and normal.
fnGetAnchorTransform(InConnector: BPC_Connector, InAnchor: BPC_Anchor, __WorldContext: Object, out OutTransform: Transform)Returns the world transform that places a connector on the given anchor component.
fnAlignRotationToNormal(InNormal: Vector, InRotation: Rotator, __WorldContext: Object, out OutRotation: Rotator)Rotates a rotator so its up axis matches a surface normal while preserving its facing as closely as possible.