Storm Game Framework 2.0.0
User guide
Loading...
Searching...
No Matches
Add your first game rule

Build a supply-room door that opens only for a character who owns the supply kit. SGF validates and dispatches the interaction. Your door Blueprint supplies the rule and the visible result.

Before you start

Complete Equip and show the item. This chapter uses Make Interaction Success and Make Interaction Failure, Blueprint nodes in StormInteraction.

In Project Settings > Gameplay Tags, add Tutorial.Interaction.Failure.KitRequired to a project tag source.

Create the door actor

  1. Create an Actor Blueprint in Tutorial/Interactions named BP_SupplyDoor. This is a new game object with its own rule, so it gets its own Blueprint.
  2. Add a Scene component named DoorPivot beneath the root, with relative location 0, -50, -100. Add a Static Mesh component named DoorPanel beneath DoorPivot. This keeps the actor origin at the closed panel's centre while the pivot sits at its lower left edge.
  3. Give DoorPanel the Engine Cube, set Mobility to Movable, Collision Presets to BlockAllDynamic, relative location to 0, 50, 100, and scale to 0.10, 1, 2. Its left edge should meet the pivot.
  4. In Class Defaults, enable Replicates. Add a Boolean variable Open, initially false, with Replication > RepNotify.
  5. In OnRep_Open, use a Select Rotator driven by Open: closed 0, 0, 0; open with Z (Yaw) = 90 and X (Roll) and Y (Pitch) left at 0. Pass it to DoorPivot > Set Relative Rotation. Use an absolute rotation each time, so repeated notifications produce the same pose.
  6. Add an object-reference variable RequiredKit of type Storm Item Archetype, default DA_SupplyKit.
  7. In Class Settings > Interfaces, add Storm Interactable. Compile.

Blueprint's RepNotify setter runs the notification on the server too. Clients receive Open and apply the same rotation. The door's meaning belongs to your game; the interaction component does not define an Open command.

Write the ownership check

In BP_SupplyDoor, create HasRequiredKit with an Actor input named Interactor and a Boolean output named HasKit. In the function's Details, expand Advanced and enable Const. It reads state and changes nothing; Const also lets the read-only Can Interact interface function call it. A local Found variable is still allowed.

  1. Add a local Boolean Found, set false at the function's start.
  2. Check Is Valid on Interactor, then Does Implement Interface > Storm Inventory Owner. Return false if either check fails.
  3. Call Get Primary Inventory on Interactor and check that the returned inventory is valid. Call Get Inventory Entries on it.
  4. Run a For Each Loop with Break over the entries. Break each entry and its Item reference.
  5. Compare the entry's Definition Id with Get Primary Asset Id From Object targeting RequiredKit, using Equal (PrimaryAssetId). Also require its Quantity > 0.
  6. When both are true, set Found true and break the loop. Connect Completed to the function's return with HasKit = Found.

Return false for a missing inventory. Do not read another player's pawn through Get Player Character 0 here: use the Interactor supplied to the function.

Implement the interaction result

Open Can Interact under the Blueprint's interface functions. Call HasRequiredKit with the provided Interactor. Return Make Interaction Success when true; otherwise return Make Interaction Failure with Tutorial.Interaction.Failure.KitRequired. This is a read-only availability query.

Open Interact and repeat the ownership check there. On false, return the same failure without changing Open. On true, set Open to true and return Make Interaction Success. Compile and save.

Checking again in Interact matters: availability may have changed since a prompt was drawn. SGF dispatches the final call on the server, and that call must decide from the server's current inventory. Repeated successful interactions leave the door open.

Ask SGF to interact with the selected target

Open BP_PlayerCharacter and add a Storm Interaction component named Interaction. In its Rules, set Max Range = 300, Require Line Of Sight on and Line Of Sight Channel = Visibility. Keep the character and component replication enabled.

In its Event Graph, add keyboard 5. On Pressed:

  1. Require Is Locally Controlled and Is Character Ready.
  2. Get Actor Eyes View Point for the start of a trace. Use Get Control Rotation > Get Forward Vector, multiply by 300, and add it to the start for the end.
  3. Call Line Trace By Channel, channel Visibility, with Ignore Self enabled. The door panel must block this channel.
  4. If the trace hit, break Out Hit and pass Hit Actor to Interaction > Request Interact.

The trace is your game's target selection. The server repeats SGF's range and sight checks and gets the interactor from the component's owner. The client sends a target, not a claim that the rule already passed.

Select Interaction and add On Interaction Result. Break its Result and branch on Succeeded. Print Door opened for success. For the kit-required Failure Tag, print You need a supply kit; use Interaction refused for other failures. A failed immediate Request Interact result can also be printed as a submission failure. On a client, a successful submission is not the final door result.

Play and check

Place BP_SupplyDoor about 200 cm in front of the Player Start, with its actor origin 100 cm above the floor so the panel rests on it. Keep the origin clear of walls: SGF's sight check aims at the actor origin, and putting it at a hinge against a wall or on the floor can produce a blocked-sight refusal. Face the panel and press 5. With the kit, it should open. Stop Play, clear the game mode's Starter Item and temporarily empty the starting loadout. Play again: the door should stay closed and report that the kit is required. Restore the grant and loadout afterwards.

Walk beyond 300 cm or put a blocking wall between character and door: the interaction should refuse. For multiplayer, use two PIE players with a listen server. Check the requesting client's result and both players' view of the door. A newly joined client should see the current Open state; test that separately before shipping.

If something does not match

Symptom Check
The trace hits nothing. Face the panel, stay within reach, and check Visibility collision.
Every request fails. Check Max Range, the interface implementation and the component's owner.
A client says submitted but the door stays closed. Read On Interaction Result and its Failure Tag.
Only the server sees the door open. Enable actor replication and apply rotation from OnRep_Open.
The no-kit test makes the character unready. Empty the starting loadout as well as clearing the grant.

Checkpoint: the server opens the door for a kit owner and refuses without changing it for a character without the kit. Opening does not consume the kit.

Next: Add a screen.