Skip to content

Add a replicated action

You add a noise barrel: a metal barrel that survivors bang to draw the zombies away from where they are. You need a gameplay tag, a timed action and a child Blueprint of BP_Interactable.

The gesture follows the template's network rules. The player's machine only asks. The host checks and applies, and the result reaches every machine as replicated state. Architecture describes that path, so read it first.

Steps

1. Declare the tag

  1. Open Edit > Project Settings > Gameplay Tags, then Manage Gameplay Tags.
  2. Add Action.Barrel.Bang next to the other Action.* tags. The tags are kept in Config/DefaultGameplayTags.ini.

2. Create the action

  1. Open Content/ZombieSurvival/DataAssets/Actions/Childs/.
  2. Duplicate DA_Action_GeneratorToggle and name the copy DA_Action_BarrelBang. It is already a short gesture on an object: the survivor walks to it (bApproachTarget) and the reach is 160 uu (Range).
  3. Open the copy and set:
Field Value What it does
ActionTag Action.Barrel.Bang the tag of step 1; the barrel recognises its action by it
DisplayName Bang the name in the action queue on screen
BaseDuration 1.5 seconds before the effect, with a progress bar above the survivor
bRequireClearLine ticked refused through a wall
bCancelOnMove ticked walking away cancels it

Save.

3. Register it

  1. Open DA_ActionRegistry_Default, in the same folder.
  2. Add DA_Action_BarrelBang to ActionDefs.
  3. Save.

The host refuses any action that is not in this registry, with This action is not allowed.

4. Create the Blueprint

  1. Open Content/ZombieSurvival/Blueprints/Interactables/.
  2. Right-click BP_Interactable, Create Child Blueprint Class, and name it BP_NoiseBarrel.
  3. Open it. In Components, select Mesh and set its Static Mesh to Meshes/Environments/Props/SM_Prop_Barrel.

BP_Interactable already implements BPI_ActionTarget, the context menu and the reach checks. The child only adds its own action.

5. Add the variables

In My Blueprint, add these variables. Put the first two in a category No Edit, with Instance Editable unticked, and the other four in Settings, with it ticked.

Variable Type Default What it is
BangCount Integer 0 how many times the barrel was banged. Set its Replication to RepNotify: the host writes it, every machine receives it
LastBangTime Float -100 when it was last banged, on the host
CooldownSeconds Float 4 how long it refuses after a bang
BangSound Sound Base (object reference) Audios/Interactions/SW_Craft_Hammer the sound of a bang
BangAttenuation Sound Attenuation (object reference) Audios/SA_Default how far the sound carries
NoiseTag Gameplay Tag Noise.Craft.Hammer what the zombies hear. It must be a row of the noise table, DA_NoiseSettings_Default

Leave Replication on None for the other five. Setting BangCount to RepNotify creates the function OnRep_BangCount. Compile.

6. The menu entry

  1. In My Blueprint, Functions, Override, pick Collect Entries. An event Event Collect Entries appears in the Event Graph. Its Who output is the survivor who opens the menu.
  2. From it, call Add Action Entry, a function of BP_Interactable, with Who = Who, Tag = Action.Barrel.Bang, Label = Bang the barrel and Params = a Make S_ActionParams node with its defaults.

Add Action Entry finds the action by its tag and runs your check at once, so an entry that would be refused shows its reason.

7. The check, on the host

Override Can Extra Act By. It receives Tag, Who and Params, and returns bHandled, bOk and Reason. Build:

  1. Matches Tag with Tag One = Tag, Tag Two = Action.Barrel.Bang and Exact Match ticked, then a Branch on its result.
  2. On False, the tag belongs to another action: Return with bHandled unticked. The parent class then handles the tag as usual.
  3. On True, a second Branch on Get Game Time in Seconds < LastBangTime + CooldownSeconds.
    • On True, Return with bHandled ticked, bOk unticked and Reason = The barrel is still ringing.
    • On False, Return with bHandled and bOk ticked.

The host calls this check when the request arrives and again when the time is up. A refusal sends its reason to the player who asked.

The label of step 6 and the reason are plain text. If you translate the game, make them entries of the string tables ST_HUD and ST_Messages, as the template's own texts are.

The pictures of steps 7 to 9 show each graph cut into rows, read from top to bottom: a wire that leaves a row on the right comes back on the left of the next. Click a picture for the graph in one piece.

Can Extra Act By: the tag typed in Tag Two, the reason typed in the Return node.

8. The effect, on the host

Override Extra Act By. It receives Tag, Who and Params, and returns bHandled and bDone.

  1. The same Matches Tag and Branch as in step 7. On False, Return with both unticked.
  2. On True:
    1. Set LastBangTime to Get Game Time in Seconds.
    2. Set BangCount to BangCount + 1. Because the variable is RepNotify, the node is Set w/ Notify: it runs OnRep_BangCount on the host, and the new value reaches every client, where OnRep_BangCount runs too.
    3. Call AlertZombies (step 9).
    4. Return with bHandled and bDone ticked.

The barrel is dormant on the network, like every interactable. A Set on a replicated variable of the actor wakes it, so nothing more is needed.

In the picture, the 1 comes from a Make Literal Int node. Typing 1 in the second pin of + does the same.

Extra Act By: the tag check, then Set LastBangTime, BangCount + 1 through Set w/ Notify, Alert Zombies and the Return.

9. The noise the zombies hear

Add a function AlertZombies. It does what every noise source of the template does:

  1. Get Game Mode, then Cast To BP_ZSGameMode.
  2. On the cast result, Noise Loudness with Source Tag = NoiseTag. It reads the loudness of that row in the noise table.
  3. Get All Actors Of Class with Actor Class = BP_Zombie, and a For Each Loop on the result.
  4. In the loop body, Get Controller of the element, Cast To AIC_Zombie, then Hear Noise From on it, with Location = Get Actor Location (of the barrel), Loudness = the loudness of step 2 and Source Tag = NoiseTag.

Each cast goes on only when it succeeds, so no Is Valid node is needed. Each zombie decides on its own whether the noise reaches it, from its hearing range and the loudness. The function runs on the host only, because Extra Act By does.

AlertZombies: the game mode cast, Noise Loudness, then the loop over the zombies and Hear Noise From.

10. The sound on every machine

Open OnRep_BangCount:

  1. A Branch on Get Game Time Since Creation > 1.0.
  2. On True, Play Sound at Location with Sound = BangSound, Location = Get Actor Location and Attenuation Settings = BangAttenuation.

The branch is for a player who joins later. Their copy of the barrel is created with the current count, and OnRep_BangCount runs once at that moment. Without the branch, they would hear a bang that happened before they arrived. A player joining late has not been tried.

Compile and Save.

11. Put one on Pine Hollow

  1. Open Content/ZombieSurvival/Maps/L_World. The editor loads the North quarter.
  2. Drag BP_NoiseBarrel into the map, on the pavement next to the four PlayerStart actors of that quarter.
  3. Save the map with File > Save All. On a World Partition map the barrel is saved in a file of its own.

Check that it works

Play with two players in the editor, a host and a client.

The client's context menu on the barrel: the entry added by Collect Entries.

  1. In the client's window, tap Right mouse on the barrel. The menu offers Bang the barrel.
  2. Pick it. The client's survivor walks to the barrel, a bar fills above it for one and a half seconds, Bang shows in the action queue, then the sound plays in both windows.
  3. Pick it again while the first bang runs. When the second one ends, the host refuses it, and the client reads The barrel is still ringing.
  4. Bang it from the host's window. The client hears it too.
  5. A zombie within earshot, 10 m away for example, turns and walks to the barrel.

A second bang during the cooldown: the host refuses it and the client reads the reason.

If it does not work

  • The menu has no entry: Event Collect Entries is not wired, or the tag in Add Action Entry does not match ActionTag of the action exactly.
  • The host answers "This action is not allowed": DA_Action_BarrelBang is not in ActionDefs of DA_ActionRegistry_Default.
  • The entry is there but always greyed, or refused with another reason: the parent's checks ran instead of yours, because Can Extra Act By returns bHandled unticked for your tag.
  • The host hears it, the client does not: BangCount is not RepNotify, or the sound is played in Extra Act By instead of OnRep_BangCount. Extra Act By runs on the host only.
  • No zombie comes: they are too far for that row of the noise table. Try a louder NoiseTag, such as Noise.Gunshot.Pistol, or stand closer. Tune the systems lists the rows and their radii.
  • The check never refuses: LastBangTime is not set in Extra Act By, or CooldownSeconds is 0 on the placed barrel.
  • Even the first bang is refused with The barrel is still ringing: LastBangTime is set in Can Extra Act By instead of Extra Act By. The check runs before the effect and again when the time is up, so it must not start the cooldown.

Keep the count across a save

The barrel's count is not saved. Every state the world save keeps follows one path, and the fuel pumps are its smallest example. To keep the count, add the same three pieces:

Piece The pumps The barrel
A struct of the saved state, keyed by the actor's SaveId Blueprints/Structs/S_SavedPump (SaveId, Stock) S_SavedBarrel (SaveId, BangCount)
An array of that struct in the world save SvPumps on Blueprints/Core/SG_World SvBarrels
Two functions of Blueprints/ActorComponents/AC_WorldPersistence, the component of the game mode that writes and reads the world CollectPumps, when the host saves; RestorePumps, after a load CollectBarrels, RestoreBarrels, called next to them

CollectBarrels walks the placed barrels and adds one row per barrel. RestoreBarrels finds each barrel by its SaveId and sets BangCount back. Both run on the host: the clients receive the count through its replication, as in play.

BP_Interactable already carries a SaveId. After you place barrels in a map, run Assign Save Ids and Validate Save Ids, as Save, load and death shows, then check in the Details panel that each barrel has one.

Leave SaveVersion of SG_World as it is: a world saved before your change loads, with the new array empty. Raising it makes the game refuse the older saves. A field added to an existing S_Saved* struct follows the same rule, but renaming or retyping a field loses the value saved under it.

Do not copy the generator of the large map. It is saved another way, by BP_ZoneManager (SaveGenerators, LoadGenerators), an actor that exists only on a World Partition map such as Pine Hollow.