PurrNet
  • 🐈Introduction
    • ‼️Unique to PurrNet
    • 💲Pricing
    • 💻Compatibility
    • 📚Addon library
    • 🗺️Roadmap
    • 🏎️Performance
      • RPC Benchmarks
      • Network Transform benchmarks
    • 🥰Support PurrNet
  • 🏁Getting Started
    • Installation
    • Minimal Setup
    • Converting to PurrNet
      • Converting from Mirror
      • Converting from FishNet
  • 📚Simple Guides
    • Easy Multiplayer Physics (input Sync)
  • 🖥️Systems and modules
    • Network Manager
      • Network Rules
      • Network Prefabs
      • Network Visibility
        • Distance condition
      • Authentication
    • Transports
      • Composite Transport
      • UDP Transport
      • Web Transport
      • Local Transport
      • Steam Transport
      • Purr Transport
      • Simulating latency
    • Network Identity
      • Ownership
      • Spawning & Despawning
      • NetworkBehaviour
      • Don't destroy on load
    • Network Modules
      • Common Pitfalls
      • Sync Types
        • SyncVar
        • SyncList
        • SyncArray
        • SyncQueue
        • SyncDictionary
        • SyncEvent
        • SyncHashset
        • SyncTimer
        • SyncInput
    • Remote Procedure Calls
      • Generic RPC
      • Static RPC
      • Awaitable RPC
      • Direct Local Execution of RPCs
    • Broadcasts
    • Scene Management
    • Client Side Prediction
      • Overview
      • Predicted Identities
      • Predicted Hierarchy
      • Best Practices
      • Input Handling
      • State Handling
    • Instance Handler
    • Collider Rollback
    • BitPacker
      • Networking custom classes, structs & types
  • Plug n' play components
    • Network Transform
    • Network Animator
    • Network Ownership Toggle
    • Network Reflection
    • Network State Machine
  • 🎮Full game guides
    • 🔫First Person Shooter
    • 🪓Survival Game
  • ✊Community Guides
    • Chat system with broadcasts
  • 🧩Addons
    • Lobby System
  • 🤓Terminology
    • Early Access
    • Channels
    • Client Auth/Everyone (Unsafe)
    • Host
    • Server Auth (Safe)
    • PlayerID
  • 💡Integrations
    • Dissonance
    • Cozy Weather
Powered by GitBook
On this page
  1. Systems and modules
  2. Network Identity

Spawning & Despawning

PreviousOwnershipNextNetworkBehaviour

Last updated 5 months ago

Spawning and Despawning in PurrNet is as easy as instantiating and destroying in Unity! If the object contains a network identity (example your own scripts or the prefab link, network transform, etc.), it will automatically be spawned for other clients.

You can also easily drag and drop prefabs from your project into the scene in the Unity Editor, and it should just work as well!

Keep in mind that for spawning and despawning the need to allow your relative role to the object to spawn or despawn it. With the unsafe rules, everyone can do it.

public NetworkIdentity myObject;
private NetworkIdentity _spawnedObject;

private void SpawnMyObject() {
    //This will auto spawn the object
    _spawnedObject = Instantiate(myObject);
    
    //This will spawn it with the ownership
    _spawnedObject.GiveOwnership(localPlayer);
}

private void DespawnMyObject() {
    //Similar to what you do in Unity, just destroy the gameobject and it'll despawn
    if(_spawnedObject)
        Destroy(_spawnedObject.gameObject);
}
🖥️
network rules