LogoLogo
⚠️ Outdated documentationGo to LatestHomeAPI
SDK 0.10
SDK 0.10
  • Welcome
  • Overview
    • What is coherence?
    • How does coherence work?
    • Rooms and Worlds
    • Features and Roadmap
    • Release Notes
    • Known Issues and Troubleshooting
  • Learning coherence
    • First Steps tutorial
      • 1. Basic syncing
        • 1.2. Animation parameters
        • 1.3. Sending commands
      • 2. Physics / Authority transfer
      • 3. Areas of interest
      • 4. Parenting entities
      • 5. Complex hierarchies
      • 6. Persistence
    • How to network...
      • Racing
      • Turn-based
      • First-Person Shooter
      • MMO
      • Fighting
  • Get started
    • Installation
    • Scene Setup
      • Sample UI
    • Prefab Setup: CoherenceSync
    • Local Development
      • Tips and Recommendations
    • coherence Cloud
      • Create a Free Account
      • Deploy a Replication Server
      • Share Builds
  • coherence SDK for Unity
    • Components
      • CoherenceSync
      • CoherenceMonoBridge
      • CoherenceLiveQuery
      • CoherenceTagQuery
      • Order of execution
    • Networking State Changes
      • Messaging with Commands
      • Hierarchies & Child Objects
        • Child GameObjects
        • Child CoherenceSyncs
        • Deep Child CoherenceSyncs
      • Animations
      • CoherenceSync References
      • [Sync] and [Command] Attributes
      • [OnValueSynced] Attribute
      • Supported Types
      • Player Name (Sample UI)
    • Baking (Code Generation)
    • Authority
      • Authority transfer
      • Server-authoritative setup
    • Lifetime
      • Persistence
      • Example – a global counter
    • Optimization
      • Simulation Frequency
      • Areas of Interest
      • Level of Detail (LOD)
    • Interpolation
    • Settings
    • Simulation Frame
    • Replication Server
    • Simulators
      • Scripting: Client vs Simulator
      • Local Development
      • World Simulators
      • Room Simulators
      • Simulator Slugs
      • Multi-Room Simulators
      • Build and Publish
      • Command-line arguments
      • Load Balancing
      • Network Connectivity
    • Client Connections
    • Rollback Networking Support
    • Floating Origin
    • CLI
  • coherence API
    • Worlds
    • Rooms
    • PlayResolver
    • DescriptorProvider
  • Developer Portal
    • Overview
    • Dashboard
    • Worlds
    • Rooms
    • Game Services
      • Account
      • Key-Value Store
      • API
        • Game account
        • Key-value store
  • Schema explained
    • Overview
    • Specification
    • Field settings
    • Archetypes
  • Additional resources
    • Community
    • SDK Upgrade Guide
    • Video Tutorials
    • Quick Samples
    • Continuous Integration
    • Unreal Engine Support
    • WebGL Support
    • Peer-to-Peer Support (P2P)
    • Pricing
    • SLA
    • Glossary
Powered by GitBook
On this page
  • Controls
  • Topics covered
  • In this scene...
  • How it's set up

Was this helpful?

Export as PDF
  1. Learning coherence
  2. First Steps tutorial
  3. 1. Basic syncing

1.3. Sending commands

Last updated 2 years ago

Was this helpful?

Using the same scene as in the , we now take a look at another way to make Clients communicate: Network Commands. Network Commands are like sending direct messages to objects, instead of syncing the value of a variable.

Controls

  • WASD or Left stick: Move character

  • Hold Shift or Shoulder button left: Run

  • Spacebar or Joypad button down: Jump

  • Q or D-pad up: Wave

Topics covered

|

In this scene...

Building on top of previous examples, let's now focus on two key player actions. Press Space to jump, or Q to wave. For both of these actions to play their animation, we need to send a command over the network to call Animator.SetTrigger() on the other Client.

How it's set up

Like before, select the player Prefab located in the Characters/Player __ folder, and browse the Hierarchy until you find the sub-object called PlayerModel.

Open the coherence Configure window on the Methods tab:

You can see how the method Animator.SetTrigger(string) has been marked as a Network Command. Once this is done, it is possible to invoke it over the network.

You can find the code doing so in the Hail class (located in /Scripts/PlayerActions/Hail.cs):

sync.SendCommand<Animator>(nameof(Animator.SetTrigger), MessageTarget.Other, "Hail");

With this simple line of code, we're asking to:

  • Send a command to an object of class Animator.

  • Invoke a method called Animator.SetTrigger.

  • Do so only for network entities other than the one with authority (MessageTarget.Other).

  • Pass the string "Hail" as the first parameter (which is the name of the animation trigger parameter).

Because we don't invoke this on the one with authority, you will notice that just before invoking the Network Command, we also call SetTrigger locally in the usual way:

animator.SetTrigger("Hail");

An alternative to avoid this would have been to pass MessageTarget.All to CoherenceSync.SendCommand(), but in this case it made more sense to avoid that additional network traffic and just execute locally.

In this example we used a Network Command to trigger a transition in an animation state machine, but they can be used to call any instantaneous behavior that has to be replicated over the network. As an example, it is also used in the sample to change a number in a UI element across all Clients.

Persistence
previous lesson
Network Commands
Animation
Two connected players waving at each other.