Skip to reading
Action Lists & Events

34. Watch an attach-point contact

Edition 0.86.4.3

0.86.4.3 edition with revised lessons, updated cross-references and new cinematic/camera-safety supplements. Earlier examples, screenshots and registry figures retain their stated edition context.

Download PDFView PDF page

Attach-point contact is useful when the important event is "these two named points meet" rather than "the player entered this large volume." A tool touching a socket is a good example.

1. Create a named point on the tool and a named socket point on the target.

2. Check their coordinate spaces, positions, enabled state and contact radii.

3. Start Watch Attach Point Contacts with a stable Watch ID, such as tool_touch.

4. Subscribe a script or On Event graph to OnAttachPointContact.

5. Filter watchId and phase. On the first valid enter, set your success flag before rewarding the player.

6. Stop the watch when the puzzle phase ends or the tool is put away.

Code example
func on_attach_point_contact(event: Dictionary = {}) -> Variant:
    if event.get("watchId", "") != "tool_touch":
        return false
    if event.get("phase", "") != "enter":
        return false
    if Runtime.variables.get("socket_done", false):
        return false
    await SetVariable({"name": "socket_done", "value": true})
    await StopAttachPointWatch({"watchId": "tool_touch"})
    return true

Swept detection can catch contact that happens between samples. It can report a quick enter and exit in a short interval. That is why the phase filter and one-time success flag matter.

Attach Points Touching returns a value; If Attach Points Touching branches a graph; Watch Attach Point Contacts creates a continuing watch. Choose the one that matches the job.

Page 39 of 189Permalink
Go to page