npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

com.phantomsxr.xrmodnetcodemodule

v1.0.14

Published

Netcode for GameObjects is a high-level netcode SDK that provides networking capabilities to GameObject/MonoBehaviour workflows within Unity and sits on top of underlying transport layer.

Readme

XRMODNetcode Module

The XRMODNetcode module provides a comprehensive, production-ready networking layer built on Unity Netcode for GameObjects. It simplifies multiplayer development by offering session management, object pooling, RPC utilities, and specialized systems like tabletop networking.

🚀 Key Features

  • Unified Session API: Create, join, and manage multiplayer sessions with client-server, Unity Relay, or distributed authority topologies
  • Network Object Management: Simplified spawning, despawning, and registration of network prefabs and player objects
  • Tabletop System: Ready-to-use seat management for turn-based or tabletop experiences
  • Lag Compensation: Built-in tools for client-side prediction and server reconciliation
  • Object Pooling: Efficient NetworkObjectPool for frequently spawned/despawned objects
  • Custom Network Variables: Extended variable types for strings, Unity primitives, and custom data
  • Message Bridge: Seamless integration with XRMOD's UnityFusion messaging system

📦 Module Structure

  • NetcodeServiceAPI.cs: Main singleton API for session and object management
  • Models: Configuration classes (BaseSessionConfig, HostingBaseSessionConfig, topology types, regions)
  • Components: Network behaviors, XRI integration, lag compensation, and network discovery
  • Systems/TabletopSystem: Seat assignment, player connection handling, and tabletop game logic
  • NetworkVariables: Custom network-synchronized variable types
  • NetworkSerializable: Serializable data structures for network transmission
  • Utilities: Message readers/writers, object pooling, and NetworkManager extensions
  • EventArgs: Event argument classes for netcode lifecycle events

🛠 Getting Started

Creating or Joining a Session

Use NetcodeServiceAPI to create or join multiplayer sessions:

using Phantom.XRMOD.NetcodeModule.Runtime;

// Configure session
var config = new BaseSessionConfig
{
    SessionCode = "MyGameRoom",
    MaxPlayer = 4,
    TopologyTypes = NetworkTopologyTypes.UnityRelay,
    Private = true
};

// Create or join session
var session = await NetcodeServiceAPI.GetInstance.CreateOrJoinSession("MyGame", config);
Debug.Log($"Joined session: {session.Name}");

Spawning Network Objects

Register and spawn networked prefabs:

// Register a network prefab
NetcodeServiceAPI.GetInstance.RegisterPrefab(myNetworkPrefab);

// Spawn a network object (server/host only)
var spawnedObject = NetcodeServiceAPI.GetInstance.SpawnNetworkGameObject(
    myNetworkPrefab,
    Vector3.zero,
    Quaternion.identity
);

// Spawn as a player object
var playerObject = NetcodeServiceAPI.GetInstance.SpawnPlayerGameObject(
    clientId,
    playerPrefab,
    spawnPosition,
    Quaternion.identity
);

Using the Tabletop System

The tabletop system automatically manages seats for turn-based games:

// Request any available seat
TableTopNetworkedSystem.GetInstance.RequestAnySeat(NetworkManager.LocalClientId);

// Request a specific seat
TableTopNetworkedSystem.GetInstance.RequestSeat(seatId: 2);

// Subscribe to seat change events
TableTopNetworkedSystem.GetInstance.OnJoinSeat.AddListener(() => {
    Debug.Log("Joined a seat!");
});

Network Variables

Network variables in XRMOD are component-based. They must be attached to the same GameObject as an XRMODNetworkBehaviour and are retrieved via a unique Key.

using Phantom.XRMOD.NetcodeModule.Runtime;
using UnityEngine;

public class PlayerProfile : XRMODBehaviour
{
    // These components should be attached to the same GameObject
    private Fixed32StringNetworkVariable playerNameVar;
    private XRMODNetworkBehaviour networkBehaviour;

    private void Awake()
    {
        // Get the bridge component
        networkBehaviour = GetComponent<XRMODNetworkBehaviour>();
        
        // Retrieve variables by their Key (set in Inspector or via nameof)
        if (networkBehaviour.TryGetNetworkVariable(nameof(playerNameVar), out playerNameVar))
        {
            // Subscribe to changes if enabled
            playerNameVar.OnValueChanged.AddListener((oldVal, newVal) => {
                Debug.Log($"Name changed: {newVal}");
            });
        }
    }

    public void UpdateName(string newName)
    {
        if (networkBehaviour.IsServer) // Only server/owner can write by default
        {
            playerNameVar.Value = newName;
        }
    }
}

💡 Best Practices

  1. Use NetcodeServiceAPI: Always access networking features through the singleton NetcodeServiceAPI.GetInstance
  2. Register Prefabs Early: Register all network prefabs before starting the session
  3. Choose the Right Topology:
    • ClientServer: For competitive games requiring authoritative server logic
    • UnityRelay: For peer-to-peer casual games without dedicated servers
    • DistributedAuthority: For cooperative experiences with no single authority
  4. Handle Disconnections: Subscribe to OnPlayerStateChanged to handle player joins/leaves gracefully
  5. Use Object Pooling: For frequently spawned objects (projectiles, effects), use NetworkObjectPool

⚠️ Common Pitfalls

  • Missing Prefab Registration: Spawning fails if prefabs aren't registered via RegisterPrefab() first
  • Server-Only Operations: Methods like SpawnNetworkGameObject only work on the server or host
  • Session Mismatch: Ensure all clients use the same SessionCode and gameName when joining
  • Region Selection: For Unity Relay, choose the region closest to your target audience for best latency
  • Topology Limitations: Not all features work in every topology (e.g., distributed authority has different ownership rules)

🔌 Integration with XRMOD

The Netcode module integrates seamlessly with other XRMOD systems:

  • UnityFusion: Automatic message bridging via UnityFusionMessageBridge
  • ActionNotification: Network events posted to ActionNotificationCenter
  • XRMODInput: XRI-aware network behaviors for VR/AR controllers

Developed by PhantomsXR Ltd.