# Interactcraft Replicated interaction for Unreal Engine 5: look and press, hold with a progress bar, interactions that need two players, several options on one object, Gameplay Tag requirements, a prompt drawn over the object with the key of the device in use, dots on what is usable nearby, object inspection, save and load, use spots with a montage, client prediction, Behavior Tree, State Tree and Smart Object nodes for AI, and ready pieces (door, lever, keypad, pickup, chest, pressure plate). C++, with every gameplay function open to Blueprint. Uses only engine plugins: Enhanced Input, State Tree, Smart Objects and Gameplay Abilities. Support: contato@tessaroapps.com  **Start here:** [Set up in 3 steps](#set-up-in-3-steps) · [Recipes in Blueprint](#recipes-in-blueprint) · [FAQ and troubleshooting](#faq-and-troubleshooting) · [Limits of this version](#limits-of-this-version) · [Node reference](Docs/REFERENCE.md) **All sections:** [Set up in 3 steps](#set-up-in-3-steps) · [What happens when a player presses](#what-happens-when-a-player-presses) · [What is in the Content folder](#what-is-in-the-content-folder) · [The two components](#the-two-components) · [Several options on one object](#several-options-on-one-object) · [Use spots and montage](#use-spots-and-montage) · [Client prediction](#client-prediction) · [AI](#ai) · [Gameplay Ability System](#gameplay-ability-system) · [Save and load](#save-and-load) · [Ready pieces](#ready-pieces) · [The prompt](#the-prompt) · [Recipes in Blueprint](#recipes-in-blueprint) · [Moving from your own interaction code](#moving-from-your-own-interaction-code) · [C++](#c) · [FAQ and troubleshooting](#faq-and-troubleshooting) · [Network](#network) · [Limits of this version](#limits-of-this-version) ## Set up in 3 steps  1. Enable the plugin and restart the editor. 2. Add an **ITC Interactor** component to your player pawn. Any pawn works, there is no base class to inherit from. 3. Add an **ITC Interactable** component to any replicated actor, write its **Prompt** and bind **On Interacted**. An actor placed in the level works even if it does not replicate: the press reaches it, and On Interacted runs on the server. What you change there only reaches the players if the actor replicates it, so tick Replicates when other players must see the result. An actor spawned during play has to replicate for the press to reach it. Press Play. Looking at the actor shows `[E] Use`, and E fires On Interacted on the server.   [Watch these steps in the editor: a 28 s video](img/interactcraft_setup.mp4). And a 53 s trailer with a host and a client side by side at 150 ms and 5% loss: [watch it](img/interactcraft_trailer.mp4). The interactor binds its own input (E and the left face button). To use your own Input Action, set **Interact Action** on the component. To drive it yourself, turn **Set Up Input** off and call **Begin Interact** on key down and **End Interact** on key up. To see everything working first, open `/Interactcraft/Demo/Maps/L_ITCDemo`. The map brings its own game mode and character. It has 16 numbered stations: door, locked door, lever, hold button, valve, keypad, a heavy gate for two, pressure plate, code levers and code screen, inspect, an AI worker, a use spot with a montage, save and load buttons, a room in Nearest mode with Priority, and a chest. The example classes the demo uses (the character, its game mode, the AI worker and the Nearest room) sit in their own module, **InteractcraftExample**. Your game does not need them, and they cost nothing unless a map uses them: four small classes, no tick, no asset loaded, and two example Gameplay Tags (Interactcraft.Example.Engineer and Interactcraft.Example.Stunned) that the tests use. Leave `Interactcraft.uplugin` as it is; Fab installs the plugin in the engine, so a change there reaches every project and goes away with the next update. The automation tests sit in **InteractcraftTests**, a DeveloperTool module: in the editor and development builds, never in a shipped game. ## What happens when a player presses  | Where | What | |---|---| | Player's machine | The interactor finds what the player is looking at (the focus) and shows its prompt. The key press goes to the server as an RPC with the object and the chosen option. Doors and switches move here at once (prediction) | | Server | Range, sight, aim, Can Interact and your conditions, the key, the option and the cooldown are checked again. Turned down: **On Refused** here, **On Refused Locally** on the player's machine, and a predicted door goes back | | Server | The piece decides (a locked door can still say no). Then **On Interacted** and **On Option Interacted** fire, on the server only. Use them for game logic: XP, quests, inventory | | Every machine | The state that changed (Open, On, Solved) replicates, and each machine plays the move and the sound from it. **On Interacted Locally** fires on the pressing player's machine: use it for a screen or a sound only that player gets | ## What is in the Content folder | Folder | What it is | |---|---| | `Blueprints` | `BP_ITCDoor`, `BP_ITCSwitch`, `BP_ITCKeypad`, `BP_ITCPickup`, `BP_ITCChest`, `BP_ITCPressurePlate`, `BP_ITCInspectable`: Blueprint children of the ready pieces, with their sounds set. Duplicate one and swap the meshes to start a piece of your own | | `Input` | `IA_ITCInteract` and `IMC_ITCInteract` (E and the left face button), and the actions and contexts for inspecting and picking options. The interactor uses them when you bring none | | `Materials` | `M_ITCHighlight`, the outline. Color, Glow, Face Tint and Opacity are parameters: make an instance to change them | | `Sounds` | Door, gate, switch, keypad and pickup sounds, made from sine waves and noise: no credit needed | | `UI` | `WBP_ITCPrompt` (the Panel style: key and words on a dark panel) and `WBP_ITCPromptMinimal` (no panel, the key in a ring). Set one on the interactor's Prompt Widget Class, or duplicate one to start a look of your own. Accent Color sets the picked option and the ring | | `Demo` | The demo map and its colours. `Demo/Epic` holds Epic's mannequin and Level Prototyping content the demo uses; delete `Demo` and nothing else changes | ## The two components  **ITC Interactable** goes on the thing. | Setting | What it does | |---|---| | Prompt, Enabled | Replicated. Change them on the server and every player sees it. Enabled is yours: the ready pieces never write to it | | Available | The owner's own say (a solved keypad, a lever already pulled). The ready pieces set it. The key needs Enabled and Available | | Range | Reach for this object in cm. 0 uses the player's Interact Range | | Parts | Names of the actor's components that are this object (the peephole of a door, the wheel of a boat). Reach, sight and aim are measured to them. Empty: the whole actor | | Use Cooldown Seconds | Wait after a use before anyone can use it again. Door and switch come with 0.25 s, so a key flicked in a loop does not hand out actions ten times a second | | Hold Seconds | Above 0 the key has to be held. The progress lives on the object, so every player sees the same bar | | Keep Progress | Off: letting go starts over (a crank). On: the progress waits (a repair), for the same option: another option starts from zero | | Required Users | Players that have to hold it at the same time. 2 makes a lid too heavy for one. When it fills, the object's On Interacted runs once, for the player who started the hold: their option is the one done, and with Consume Key only their key is used up. Every holder still needs the key to hold. Each holder's own interactor gets On Interaction Succeeded and On Interacted Locally: pay a shared reward there, or only in On Interacted for one | | Extra User Speed | How much faster each extra player makes a hold | | Required Key Id, Consume Key | The player needs this key on their interactor | | Required Tags, Blocked Tags | Gameplay Tags the player must have (all of them) or must not have (any one): Role.Engineer to repair, State.Carrying to keep hands busy. Read from the pawn, its components (an Ability System Component counts) and its player state, on the server and on the player's machine. **Passes Tag Requirements** answers it for a player | | Options | More than one thing to do with it. See "Several options on one object" | | Priority | When several things are in reach, the higher number wins before distance does: a chest behind an NPC still gets the key in Nearest mode, a button on a door wins over the door. 0 for most things | | Prompt Offset, Show Marker | Moves the prompt drawn over the object; turns its nearby dot off | | Highlight When Focused | The outline goes on this object's meshes (its Parts, when set) while a player looks at it | Events: On Interacted (server; a use the piece itself turned down, like a locked door shaken without the key, does not fire it, count in Get Times Used or start the cooldown), On Interacted Locally (the pressing player's machine: open a screen, play a sound), On Option Interacted, On Hold Started, On Hold Ended, On Hold Progress Changed (every machine: for a crank or a ring of your own), On Refused, On Refused Locally, On Focus Changed. Getters: Is Held, Get Users, Get Times Used. **Conditions without C++.** Add the **ITC Interaction Condition** interface to the actor (any actor, a Blueprint child of ITC Door included) and implement **Can Interact With**: return false to turn the player down, and fill **Out Reason** ("Blue team only", "Needs a crowbar"). The reason shows in place of the prompt and reaches the player's machine with the refusal (**Get Last Refusal Text** on the interactor). Overriding **Can Interact** or **Get Prompt** in a Blueprint child of the component still works too. In C++, change Prompt, Enabled, Available, Options, Range, Hold Seconds, Required Users and Required Key Id with their Set functions. In Blueprint the Set node already does it. These Set functions only work on the server, and say so in the log when a client calls them. **Force Interact (No Checks)** on the interactable skips every check, for a script; an AI should go through its interactor. **ITC Interactor** goes on the pawn. | Setting | What it does | |---|---| | Focus Mode | Aim (first and third person) or Nearest (top-down, side view). Changed during play, change it on the server: the player's machine follows | | Interact Range | Reach in cm, from the pawn's eyes (250). An interactable's own Range wins | | Needs Clear Path | No using things through a wall | | Trace Channel | The channel the aim and the clear path trace on (Visibility). Change it when your walls block another channel | | Focus Refresh Seconds | How often the player's machine looks for what the key would use (0.1 s). The key press always looks again | | Latency Slack | Extra reach the server allows, because the player moved since pressing (150 cm) | | Aim Assist Degrees, Gamepad Aim Assist Degrees | With nothing under the crosshair, the key takes what is within this many degrees of it. 0 for mouse and 6 for gamepad as shipped | | Highlight Material | Overlay put on what the player looks at. None turns it off | | Mark Nearby, Nearby Range, Max Nearby Markers | Dots on what the player can use within 6 m, in sight, 8 at most | | Max Use Spot Distance | Farthest a use spot can be for the player to slide to it (300 cm) | | Set Up Input | Binds the interact key itself. Off: call Begin Interact and End Interact from your own input | | Toggle Hold | Accessibility: one press starts a hold and the next one lets go, so nobody has to keep the key down. Looking away still lets go. Behind the GAS ability, release your Input ID on the second press instead | | Interact Action, Mapping Context, Mapping Priority | Your own Input Action and Mapping Context. The plugin ships `IA_ITCInteract` and `IMC_ITCInteract` in `/Interactcraft/Input`, used when these are empty, so players can remap the key in Enhanced Input's user settings | | Interact Key, Interact Gamepad Key | The keys the shipped mapping uses when you bring no context of your own (E and the left face button) | | Show Prompt | Puts the prompt widget on the local player's screen. Off: draw your own from the getters | | Prompt Over Object | The prompt is drawn over the object. Off: it stays under the crosshair | | Hide Prompt While View Held | Hides the prompt and the dots while a screen holds the view. Off for a fixed, top-down or vehicle camera | | Prompt Widget Class | The prompt. Make a Blueprint child of ITC Prompt Widget to restyle it | | Inspect Distance, Inspect Size, Inspect Rotate Speed, Inspect Zoom Range | Where the inspected object floats (70 cm), how big it looks (35 cm), how fast it turns and how far the zoom goes | Advanced, under the arrow: **Min Seconds Between Presses** (0.1 s: presses closer than this are dropped, on the player's machine and on the server; lower it for a game built on mashing the key), **Max Distance From Origin To Parts** (1000 cm: Nearest mode skips an actor whose origin is further than this past its reach; raise it for a ship with its wheel 20 m from its origin), **Server Aim Check Degrees** and **Server Aim Check Distance** (75 degrees past 120 cm: the server's check that the thing is in front of the player in Aim mode). While inspecting, the mouse or right stick turns the object, the wheel or the triggers zoom, and right click or the right face button puts it back. While looking at something with options, the wheel or the D-pad picks one. These come with the shipped mapping; with your own context, map `IA_ITCOptionCycle`, `IA_ITCInspectRotate`, `IA_ITCInspectZoom` and `IA_ITCInspectExit` too. The server checks range, line of sight, Can Interact and the key again before anything happens, and, with Focus Mode on Aim, that the thing is roughly in front of the player's view (on Nearest the player does not aim, so only reach counts). A client cannot open a door from across the map or, past 120 cm (Server Aim Check Distance), behind its back, use something on its own pawn, or ask for an option by a name the object does not offer. Interactor events: On Interaction Succeeded (server and the player's machine: a toast, a stat, XP), On Interaction Refused, On Hold Started, On Hold Ended. Getters: Get Using, Get Using Option, Get Refusal Count, Get Last Refusal Text, Is Holding, Get Hold Progress. Keys: **Add Key** on the server, or place an ITC Pickup. They go with the player, not the body: a player who dies or changes pawn gets them back on the next pawn with an interactor (**Keys Go With Player**, on by default). To use your own inventory, override **Has Key** and **Consume Key** in a Blueprint child of the interactor (see "Recipes"). ## Several options on one object  Add entries to **Options** on the interactable (an Id and a Prompt each). The prompt lists them, the mouse wheel or the D-pad picks one, and **On Option Interacted** tells you which. The wheel and the D-pad are only taken while the player looks at something with more than one option. For options that depend on the player, override **Get Options** in a Blueprint child. The server checks the option again: a client cannot ask for one the object does not offer that player. Every option needs an Id; one without is left out, with a warning in the log. ITC Door does this with **Can Lock By Hand**: closed and unlocked, it offers Open and Lock to whoever has its key. A hold is for one option: a player who joins a hold already started with another option ("Repair" on a "Sabotage") is turned down. ## Use spots and montage  Add an **ITC Use Spot** component to the actor, place it where the player should stand and point its arrow at the object. A player who uses it slides there in **Move To Spot Seconds** (0.3 s as shipped) and turns that way, then the use goes on. With two spots (both sides of a door) the nearest wins; **For Interactable** ties a spot to one interactable of an actor that has several. A spot farther than the interactor's **Max Use Spot Distance** (3 m) is skipped. **On Use Spot Reached** fires when the player gets there. **Use Montage** on the interactable plays on the user's skeletal mesh on every machine: at once on the player's own, through replication on the others. A hold stops it when the hold ends (**Stop Montage When Hold Ends**). A character slides by root motion (the engine's Move To Force). The pressing player's machine applies the same one in the frame the press leaves, and the server applies its own when the press arrives, so the slide starts at once on the player's screen. It does not remove every correction: the server starts its slide when the press gets there, not on the exact move it was made on. In our test at 370 ms of lag the server sent 934 to 1,331 position corrections a round with it, against 994 to 2,027 without. Nobody's position is taken on their word: a refused press takes the slide back. A pawn without character movement is moved by the server directly, and stops at a wall. ## Client prediction In short: doors and switches react on the pressing player's screen immediately, and the server corrects them if it disagrees. The door and the switch move on the pressing player's screen at once, with their sound, and the server confirms them a ping later. A second quick press guesses from what the screen shows, so open-then-close plays both sounds once. If the server says no (a key lost on the way, another player got there first), the leaf or the lever goes back. A hold, a keypad and a pickup wait for the server. **Predict On Client** on the piece turns it off. **On Refused Locally** on the interactable tells your own pieces when to take back what they showed. ## AI The demo's worker (**ITC Example Worker**, in the InteractcraftExample module) walks between its targets and uses them with the Interact And Wait node below: a short example to read, not a production AI. The **InteractcraftAI** module, in the same plugin, has three ready nodes. All of them go through the interactor on the AI's pawn, with the same range, sight, key and option checks a player gets. - **ITC Interact** (Behavior Tree task): presses or holds the actor in a blackboard key. Succeeds on a press or when a hold fills; fails on a refusal or a hold let go. Put a Move To before it. - **ITC Interact** (State Tree task): the same, with the actor as an input. - **ITC Use Smart Object** (State Tree task) with the **ITC Interact Behavior** definition: put the definition on a smart object slot, claim the slot as usual, and the task uses the interactable of the smart object's actor and frees the slot after. **Give Up Seconds** lets go of a hold that does not fill (a lid for two with one AI on it). In a Blueprint AI, or in any graph on the server, the async node **Interact And Wait** does the same with Succeeded and Failed pins. ## Gameplay Ability System In short: optional. Put interacting behind a Gameplay Ability when you want tags, cooldowns or costs to block it; the server still checks every press. The **InteractcraftGAS** module has **ITC Interact Ability**, a Gameplay Ability, so tags, cooldowns and costs block interacting like any other ability (stunned, in a cutscene, out of stamina). It is Local Predicted: it runs at once on the player's machine and again on the server, which checks the tags, the cooldown and the cost there and charges them. A player who has the ability can only interact through it: their press counts on the server once the ability ran there, whichever of the two arrives first. A cheat that sends the press alone is turned down after 1 s. A keypad takes codes only from a player who opened it through the ability, and not while a tag blocks the ability (a stun). The cost and the cooldown are charged when the ability runs, before the server rules on range or sight, as with any predicted ability. A press the server turns down still costs: keep the cost small, or refund it from **On Interaction Done** when it says it did not go through. - On a player, bound to input: presses or holds what the interactor looks at, like its own key, and lets go when the input is released. Turn off **Set Up Input** on the interactor so the key is not bound twice. - From a gameplay event with a Target, on the server (an AI, a trigger): uses that actor, with Interactable Name, Option and Give Up Seconds as on the AI nodes. - Cancelling the ability (a stun tag, death) lets go of the hold. **On Interaction Done** tells a Blueprint child whether it went through. ## Save and load In short: one node saves the state of every piece and every player's keys to a slot, one node loads it, on the server.  On the server, **Capture State** returns the state of every door, switch, keypad, code display, pickup, chest and pressure plate in the world, and the keys of every player, to keep in your own save game. **Apply State** puts it back, with no door swinging and no sound. **Save To Slot** and **Load From Slot** do both straight to a save slot, and **Save To Slot Async** and **Load From Slot Async** write and read the file on another thread for a big world, each with an On Done event. **Loading a game while playing: Open Level And Load From Slot.** It opens the map fresh (the current one when Level is empty) and loads the slot as the new map begins play; with players connected the server travels and takes them along. A load on the running map (Load From Slot) cannot bring back an actor destroyed since the save, only skip it with a warning in the log; on a freshly opened map everything placed is there again. Load From Slot on the running map suits a checkpoint where nothing was destroyed, and a load right after your own Open Level. Your own actors: add the **ITC Saved Actor** interface in Class Settings, tick SaveGame on the variables that matter and put the actor back in shape in **State Loaded**. It always runs after the actor's BeginPlay, so what BeginPlay sets up is there and what it writes does not overwrite the save. That holds for Open Level And Load From Slot and for a load called from a BeginPlay (your Level Blueprint, say): that one waits until every actor has begun, and Apply State returns 0. - **Placed in the level**: found again by the map and their object name. The name is not the label, so renaming an actor in the Outliner keeps old saves working; deleting it, or moving it to another sublevel, does not. World Partition maps included: a cell that streams out keeps what happened in it (the door stays open, the taken key stays taken) and gets it back when it streams in, and a load or a save covers actors in cells that are not loaded. - **Spawned in play** (a key an enemy dropped, a door your game builds): saved with their class and place. Loading removes the ones spawned this session and spawns the saved ones again, so loading twice does not make two. A player's body, controllers, player states and child actors are left out of this, even with the interface: they stay as they are. A Game Mode or Game State with the interface keeps its instance and gets its saved variables back. - What a spawned actor gets back is its class, place, rotation, its SaveGame variables, and its owner and instigator (a pawn, a controller or a player state). A player still reconnecting after a map change gets theirs when their pawn is possessed. Not what it was attached to: attach it again in State Loaded if your game needs it. - **Destroyed in play**: a placed piece destroyed during play (a Destroy Actors action, or your own code) is saved as destroyed, and loading destroys it again. - **Pieces the save has no entry for** (their cell was out when it was made): a load puts them back as the level has them, so what happened to them since does not stay. - **Keys**: they belong to the player, not to the body: a player who dies and respawns, or changes pawn, keeps them. Saved by player, under their save id: what their Player State gives through **ITC Saved Player**, else a platform online id, else their seat in the game (the host is 0). **Get Player Save Id** says which. A player without a pawn when the save is made (dead, spectating) keeps theirs too. A player who is in when the save loads gets them at once; one who joins later gets them when their pawn is possessed. A player the save does not have ends the load with no keys, since the pickups are back. Keeping keys in your own inventory instead: leave the interactor's key ring empty and save your inventory as you already do. The Prompt, Options, Range, Hold Seconds, Required Key Id, Required Users and Available of each interactable are saved too, so what your game changed comes back. **This also means an old save keeps the old values:** if a patch changes Hold Seconds from 3 to 5 in the level, a player who loads an older save still gets 3. To rebalance, set the new value in State Loaded on your own actor, or in your game after the load. Loading also calls off every action still waiting out its Delay, whoever started it, and lets go of anything being held. Saves from an older version of the plugin load: fields are stored by name, so a field the old save lacks keeps its default. A save from a newer version loads what this build knows and skips the rest, with a warning in the log. ## Ready pieces  All of them are replicated actors made of engine cubes. Make a Blueprint child and swap the meshes. | Piece | Notes | |---|---| | ITC Door | Swing or Slide. Locked + Key Id needs the key. Auto Close Seconds. Opens By Hand off leaves it to switches. Can Lock By Hand lets the key holder lock it again. The leaf waits while a character stands in its way and goes on when they step out (Stop At Characters). Stop At Physics Bodies does the same for a crate that simulates physics, off as shipped | | ITC Switch | Lever. With Hold Seconds on its Interactable it is a button to hold or a valve. Auto Off Seconds makes a timed button | | ITC Keypad | Code typed on a screen, checked on the server. Mouse, keyboard digits and gamepad. After 5 wrong codes in a row the player who typed them is locked out for a while; the rest of the team still types (Lockout Per Player off: the keypad locks for everyone). Past Max Wrong Tries Per Minute (20) from everyone together, the ones who typed 3 or more of them wait, twice as long each time in a row. A player with one typo keeps typing. After 10 minutes with no lockout, the next one starts again at Lockout Seconds. The player hears how long ("Locked out: 30 s"). The server never sends the code to clients; Random Code On Server picks a new one each level. Set Code changes it during play | | ITC Code Display + ITC Code Lever | One player reads a number, the other pulls that lever. After a wrong pull no lever counts for Wrong Pull Wait Seconds (2 s), so guessing costs time | | ITC Pickup | A key (Key Id), an item for your inventory (Item Id and Count), or both. Override **Give To Player** to put the item in your inventory and return false when it is full: the pickup stays and the player is told no. On Picked Up says who took what. Respawn Seconds puts it back | | ITC Chest | Open, take, close. What is inside goes to your inventory through **Give To Player** (Item Id and Count, or a Key Id), once or again after Refill Seconds. Looted Actions and On Looted. Open and Looted are saved | | ITC Pressure Plate | Pressed Actions and Released Actions. Required Pawns for a plate for two | | ITC Inspectable | Pick up and turn around. Only the player who picked it up sees it in their hands | ### How a lever opens a door No graph needed. On the switch, add an entry to **On Actions**, set Type to **Open Doors** and pick the door in **Targets**. Add **Close Doors** to Off Actions to close it again. Keypads, code displays, pickups and pressure plates have the same action lists.  Actions: Open, Close, Toggle, Unlock and Lock Doors, Switch On and Off, Enable and Disable Interaction, Give Key, Spawn Actor, Destroy Actors, Save Game and Load Game (to a slot you name: a checkpoint lever). Each one has a Delay. When a piece runs its actions again (a switch turned on, off and on), what it still had waiting is called off first, so a door that closes 5 s after the switch starts its countdown over. Two switches whose actions flip each other stop after 16 rounds, with a warning in the log. ### Overriding a piece in Blueprint ITC Door and ITC Switch call **On Used** on the server for each use; override it in a Blueprint child to do something first (a sequence, a sound) and call the parent to go on. The door's **Get Prompt For** and **Get Options For** are overridable too, and **On Locked Try Shown** fires on every machine when someone rattles a locked door. Key Id on the door and on the key pickup can be set on spawn, so an enemy can drop the right key. ## The prompt ITC Prompt Widget builds its own layout. For your own look, make a Blueprint child and name your widgets `PromptPanel`, `KeyBox`, `KeyText`, `KeyIcon`, `PromptText`, `OptionsText`, `HoldBar`, `PlayersText`, `MarkerCanvas`, `InspectPanel`, `InspectTitle`, `InspectDescription`, `InspectHint`. All are optional, the ones you add are filled in. The prompt is drawn over the object: a little above a small one, on the middle of one taller than 140 cm. **Prompt Offset** on the interactable moves it, and overriding **Get Prompt Location** puts it anywhere. For this, `PromptPanel` has to sit in a Canvas Panel, and the dots are put on `MarkerCanvas`. While a screen holds the player's view (the keypad, or your own menu that calls Set Ignore Look Input), the prompt and the dots are hidden. In a game whose camera never takes look input (fixed, top-down, a vehicle), turn off **Hide Prompt While View Held** on the interactor. The key shown is the one mapped to the interact action on the device the player touched last. For pictures instead of letters, make an **ITC Key Icon Set** data asset and set it on the widget. ## Recipes in Blueprint **Your own inventory for keys.** Make a Blueprint child of ITC Interactor and use it on your pawn. Override **Has Key** (return whether your inventory holds an item with that name) and **Consume Key** (remove one). Doors, switches and interactables with a Required Key Id now ask your inventory. For pickups, make a Blueprint child of ITC Pickup, set Key Id to None and Item Id to your item's row name, and override **Give To Player**: add the item to the Interactor's inventory and return true, or return false when it is full.   **Your own prompt look.** Make a Widget Blueprint whose parent is ITC Prompt Widget (or duplicate `WBP_ITCPrompt` from `/Interactcraft/UI`). Add a Canvas Panel, put a panel named `PromptPanel` in it and a Text named `PromptText` inside; add `KeyText`, `HoldBar` and the others from "The prompt" when you want them. Set the widget on the interactor's **Prompt Widget Class**. **A prompt drawn by your own HUD.** Turn off **Show Prompt** on the interactor and read **Get Focused**, **Get Focused Prompt**, **Get Interact Key**, **Get Focused Options** and **Get Hold Progress** from your HUD each frame.  **A door that asks a quest.** Add the **ITC Interaction Condition** interface to a Blueprint child of ITC Door, implement **Can Interact With**: return false with Out Reason "Find the cellar key first" until your quest flag is set. **Your own piece from scratch: a crate that opens.** 1. A new Blueprint Actor, `BP_Crate`, with Replicates ticked. Add two Static Mesh components (Body and Lid) and an **ITC Interactable**; set its Prompt to "Open". 2. Add a Boolean `bOpen`, Replication set to RepNotify. In `OnRep_bOpen` turn the Lid (Set Relative Rotation, -100 on Roll when open, 0 when shut). A Blueprint RepNotify runs on the server too, so every machine turns it. 3. Bind **On Interacted** of the interactable: set `bOpen` to its opposite and call **Set Prompt** with "Close" or "Open". On Interacted runs on the server only, so the client cannot open it alone. 4. To save it: add the **ITC Saved Actor** interface in Class Settings, tick SaveGame on `bOpen`, and in **State Loaded** call `OnRep_bOpen` and Set Prompt again. 5. Drop it in the level. The outline, the prompt, the range and line of sight checks, the dots and the AI nodes already work with it.  **Interacting through GAS, step by step.** 1. Your pawn has an Ability System Component. Give it **ITC Interact Ability** with an Input ID of your choice, say 1 (Give Ability, on the server, at begin play). 2. Turn off **Set Up Input** on the interactor. 3. Bind your interact Input Action: on Started call **Press Input ID** 1 on the Ability System Component, on Completed **Release Input ID** 1. The press runs the ability; the release lets go of a hold. 4. Add an **Activation Blocked Tags** entry on a Blueprint child of the ability (State.Stunned): a stunned player now cannot press, hold or type a keypad code. **A hit stops the hold.** On your pawn's damage event (Event Any Damage, or your own health component's), on the server, call **Stop Interacting** on its ITC Interactor. The crank, valve or revive under way lets go as if the key came up: Keep Progress decides whether the bar waits. To keep a stunned player from starting again, put State.Stunned in the interactable's **Blocked Tags**. ## Moving from your own interaction code Most projects already have a line trace on E and an interface with an Interact function. To move over: 1. Put **ITC Interactor** on the pawn (or on a Blueprint child of your character) and delete your trace and your E binding. In Lyra, add it to the hero pawn data's components, and turn off **Set Up Input** if the interact key goes through your ability input. 2. On each actor that answered your Interact interface, add **ITC Interactable** and move the body of your Interact function to its **On Interacted** event. It already runs on the server, so the Server RPC you had for it goes too. 3. What your interface's "can interact" did goes to an **ITC Interaction Condition** (it can return the reason the prompt shows), and the text you drew yourself to the **Prompt** field. 4. Doors and switches you built can stay as they are, or be swapped for the ready pieces when you want saving, prediction and the hold for free. Nothing has to move at once: your old interface and the interactor can live side by side while you change the actors one by one. ## C++ Every node is a plain function on the components, so C++ reads like the Blueprint. Add `"Interactcraft"` to your module's dependencies. ```cpp // Server: a bot or a scripted event uses a door, with the same range, sight, key and option checks a player gets if (UITCInteractorComponent* Interactor = Pawn->FindComponentByClass<UITCInteractorComponent>()) { Interactor->InteractWith(Door->FindComponentByClass<UITCInteractableComponent>()); } ``` ```cpp // Your inventory answers for keys: a C++ child of the interactor bool UMyInteractor::HasKey_Implementation(FName KeyId) const { const UMyInventory* Inventory = GetOwner()->FindComponentByClass<UMyInventory>(); return Inventory && Inventory->Contains(KeyId); } ``` ```cpp // Server: a stun or a cutscene stops this player from using anything, prompt and outline included Interactor->SetInteractionEnabled(false); ``` Without C++: make a Blueprint child of the interactor and override **Is Interact Allowed** (return false while stunned). It is asked on the player's machine and again on the server. Bind your game logic to `OnInteracted` with `AddDynamic`, on the server. Every function, event and setting is listed in `Docs/REFERENCE.md` in the plugin folder, which also works with no internet. ## FAQ and troubleshooting **The prompt does not show.** Check, in order: the actor has collision that blocks the interactor's Trace Channel (Visibility as shipped); the interactable is Enabled; the player is within Interact Range of the actor's solid parts; nothing blocks the view (Needs Clear Path). The console command `ITC.Debug 1` draws the aim ray and writes why the focus was turned down. **It works in Play In Editor but not in a packaged game.** The highlight material and the shipped Input Actions sit in the plugin's content and are cooked with it; if you copied the plugin's code into your project without its Content folder, add `/Interactcraft` to the directories to always cook. **Clients see the door open, but late joiners see it closed.** Only on a Blueprint child that adds its own replicated variable: call **Send State Now** on its interactable after changing it (see "Network"). **On Interacted fires twice.** You bound it on every machine: it fires on the server only. For something on the pressing player's screen use On Interacted Locally. **The AI does not open the door.** The AI's pawn needs its own ITC Interactor, and the door has to be in that interactor's reach from where the Move To ends. The task fails with the reason in the log (`LogInteractcraft`). **My actor's state is not saved.** It needs the ITC Saved Actor interface and SaveGame ticked on each variable. Without the interface only its interactables are left as they are. ## Network State is replicated properties with OnRep, not multicast events, so a player who joins late or drops packets ends up with the same doors as everyone else. Sounds and movement play on each machine when the state changes. A player who joins late gets the doors as they stand, without the swing and the sound of something that happened before they arrived. The ready pieces sleep on the network (Net Dormancy) while nothing happens to them: the server does not look at them at all. A change wakes one, and it goes back to sleep 2 s after the last change, so an update lost on the way is sent again. A hold keeps it awake until it ends. Measured with 300 idle switches added to the demo room: the server went on looking at 10 actors, with 310 asleep, and sent 2.1 KB/s, against 1.9 KB/s without them. A Blueprint child of a ready piece that adds its own replicated variable: call **Send State Now** on its interactable after changing it, or the piece may be asleep and the change waits for the next one. Tested with a dedicated server and two clients, 150 ms of lag and 5% packet loss in each direction. **A press behind the GAS ability, in the order the server sees it.** The player's machine sends two things for one key press: the ability's activation and the interactor's press. They can arrive in either order. ``` Ability first: ability runs (tags, cost, cooldown) -> Grant Press Credit -> press arrives -> credit used, press served Press first: press arrives, no credit -> press parked (one at most) -> ability runs -> Grant Press Credit -> parked press served Never ran: press parked -> 1 s passes with no ability -> press dropped, the player's machine told ``` A second press parked while one waits turns the first one down. A credit not used within the same time is gone, so an ability that ran for something else cannot open a door later. The code is in `ITCInteractorUse.cpp` (`ServerBeginInteract`, `GrantPressCredit`, `DropParkedPress`) and the test is `GAS.ServerGate`. On the player's machine, finding the focus and the dots looks through every interactable of the world. Measured with 2,055 of them over a 200 x 200 m level, in the costlier Nearest mode: 0.24 ms per look, ten looks a second (test `Focus.ManyInteractables`). Actors whose origin is past their reach plus Max Distance From Origin To Parts cost one subtraction each. ## Limits of this version - Keys are saved under the player's save id: what your Player State gives through **ITC Saved Player** (an account or profile id), else a platform online id, else the player's seat in the game (the host is 0). With no platform, two players who join in a different order swap keys on load: give your Player State an id. - A door has its own Key Id. Setting a Required Key Id with Consume Key on its interactable as well uses two keys per opening: set the key in one place. - Windows and Linux. Not tested on consoles or mobile. - Enabling Interactcraft turns on the engine's State Tree, Smart Objects and Gameplay Abilities plugins, which the AI nodes and the ability use. - With use spots on both sides of something, a player standing right in the middle can get a different spot on their machine than on the server for one slide, which the server corrects. - Use spots keep the player's height, so they suit level floors; on a slope put the spot at the player's floor. - Level Instances: actors inside one placed in the level are saved under the instance actor's name, so the same Level Instance placed twice keeps two entries. The Save.LevelInstance test covers two copies in one session; reopening a map that has them placed has no automated test yet. A save of a level instance loaded during play does not carry to the next session, because Load Level Instance names it anew each time. - An actor spawned in play has no owner until its player is back. If that player never returns, it stays without one. - Keys go with the player inside one map. A Server Travel with no load does not carry them: save before and load after, with Open Level And Load From Slot. - A key ring holds 64 keys. With it full, a pickup or chest stays where it is and the player is refused. A Give Key action gives nothing and writes a warning to the log. - A chest with Required Key asks for it while closed. Consume Key takes it on the first opening, and again only after Refill or Reset. A keypad takes it when the right code goes in. - A keypad code typed in the level ships inside the map file. For a code nobody can dig out of the game files, use Random Code On Server or Set Code during play. - Loading a save in the same session cannot bring back an actor destroyed since: load it on a freshly opened level (the log says which). - Split screen works, but the outline and the inspected object are seen by both players. ## Changelog ## Engine versions | Interactcraft | Unreal Engine | Platforms | |---|---|---| | 1.0 | 5.6, 5.7, 5.8 | Win64, Linux (client and dedicated server) | ## 1.0 First release. - Two components: ITC Interactor on the pawn, ITC Interactable on the thing. Aim (first and third person) or Nearest (top-down, side view), with Priority to break ties. - Press, hold with a shared progress bar, holds that need two or more players, several options on one object, cooldowns, keys, Required and Blocked Gameplay Tags. Toggle Hold for players who cannot keep a key down. - The server checks range, line of sight, aim, conditions, keys and options before anything happens. Rate limits on presses and keypad codes. - Prompt drawn over the object with the key of the device in use, dots on what is usable nearby, outline, object inspection. - Use spots that slide the player into place, use montages, client prediction for doors and switches. - Ready pieces: door (stops for a character in its way, and for physics props if you want), switch, keypad, code display and lever, pickup for keys or items, chest, pressure plate, inspectable. Action lists wire them with no graph, including Save Game and Load Game. - Save and load: placed actors (inside a Level Instance placed twice, each copy apart; tested within one session, not yet across a map reload), actors spawned in play (back with their player as owner, also for a player still reconnecting), actors destroyed in play, each player's keys, World Partition cells. Open Level And Load From Slot loads a game while playing, with the players taken along. Save and load to a slot on another thread too. - AI: Behavior Tree and State Tree tasks, a Smart Object behavior, the Interact And Wait node. Gameplay Ability System: ITC Interact Ability. - Shipped Input Actions and Mapping Contexts, remappable in Enhanced Input's user settings. Blueprint children of the pieces with sounds. - `ITC.Debug 1` shows why the thing under the crosshair is not focused. In the editor, a selected interactable draws its reach. - 80 automated tests in their own module (InteractcraftTests, never in a shipped game), the node reference in `Docs/REFERENCE.md`, a network probe with a dedicated server and two clients at 150 ms and 5% packet loss. ### Known issues Listed in the README under "Limits of this version": consoles and mobile untested, use spots meant for level floors, keys saved by join order when there is no platform online subsystem (give your Player State an id with ITC Saved Player).