🎨
UVC
  • Introduction
  • Installation
    • Installing in New Project
    • Installing in Existing Project - SCK
    • Installing in Existing Project - MCK
  • Space Combat Kit Tour
  • Mech Combat Kit Tour
  • Player Setup
  • Vehicle Framework
    • Game Agents
    • Vehicles
    • Modules
      • Module Mounts
      • Modules
      • Module Types
      • Module Attachments
      • Display Module On UI
      • Module Managers
  • Input
    • General Input
    • Vehicle Input
    • Rewired Integration
  • Player/AI
  • Spaceships
    • Speed UI
    • Space Fighters
    • Capital Ships
  • Mechs
    • Speed UI
  • Vehicle Control Animations
  • Character Enter/Exit
  • Camera
    • Camera Setup
    • Vehicle Setup
    • Secondary Cameras
    • Death Camera
  • Weapons
    • Framework
      • Triggerables System
      • Weapon System
    • Vehicle Setup
      • Vehicle Weapons
      • Cursor Aiming
    • Projectile Weapons
    • Beam Weapons
    • Missile Weapons
    • Resource Handling (Ammo/Heat)
    • Turrets
    • HUD Weapon Info
    • Health Modifier Volumes
  • Radar
    • Radar Setup
    • Target Setup
    • Target Selectors
    • Trackable Types
    • Improving Radar Performance
    • Target Notification
    • Radar Audio
  • Health
    • Health Framework
      • Health
      • Damageable
      • Damage Receiver
      • Health Modifier
      • Health Types
      • Health Modifier Types
      • Surface Types
    • Vehicle Setup
    • Damageable Object Setup
    • Detonators
    • Health Recharge
    • Health UI
    • Energy Shield
    • Damageable Module Linkers
  • HUD
    • HUD Basics
    • HUD Manager Setup
    • Custom HUD Components
    • HUD Module Display
    • Camera View Management
    • HUD Cursor / Reticle
    • Weapon UI
    • Resource Container UI
    • 2D Radar
    • 3D Radar
    • Target Boxes
    • Target Holograms
    • Minimaps
    • HUD Distance Lookup
  • Loadout
  • AI - Space Combat Kit
    • AI Setup
    • AI Spaceship Behaviours
  • AI - Mech Combat Kit
  • Game States
  • Teams
  • Floating Origin
  • Object Pooling
  • Menus
    • Creating Menus
    • Button Controllers
  • Rumbles
  • Rigidbody Characters [WIP]
  • Utilities [WIP]
    • Object Triggers
    • Shadow Caster Doubles
    • Gimbals
    • Game State Post Process Enabler
  • Objectives
  • Resources System
    • Resource Containers
    • Resource Handlers
    • Resource Container Triggers
    • Module/Vehicle Resource Usage
    • UI
  • Cutscenes
  • URP Upgrading
Powered by GitBook
On this page
  • Scene Setup
  • Spawn A Pooled Object
  • Returning An Object To The Pool
  • Setting Up Object Pools

Was this helpful?

Object Pooling

To make your game more efficient and run smoother, you will likely want to use object pooling for objects that are often created and destroyed, such as projectiles, explosions and temporary effects. This avoids lag and unnecessary garbage collection, which occurs when objects are destroyed in the scene and slows down your game.

Scene Setup

Simply add a Pool Manager component anywhere in your scene. This is a singleton, which means there should only be one of them in the scene at any time.

The pool manager can be accessed from anywhere in the scene very easily using the PoolManager.Instance reference.

Spawn A Pooled Object

The easiest way to spawn a pooled object is to use the Pool Manager's Get function and pass a prefab reference. This function will create an object pool for the prefab (if it doesn't already exist), and return one item at the specified position and rotation (there is also an optional parameter for setting the item's parent transform);

// Get a pooled object at a specified position and rotation
PoolManager.Instance.Get(myPrefab, somePosition, someRotation);

It's also possible to get a pooled object by name, if the prefab exists in a Resources folder. Here's an example for a prefab named 'Projectile'.

// Get a pooled instance of the prefab named 'Projectile' in a Resources folder
PoolManager.Instance.Get("Projectile", somePosition, someRotation);

Returning An Object To The Pool

To return an item to the pool, simply deactivate its game object. This will make it available for other scripts to use.

The UVC kits include a Deactivate After Lifetime component, which can be used on projectiles, hit effects and other effects to disable them a specified time after they are spawned to return them to the pool.

Setting Up Object Pools

When you get an object for the first time from the pool manager, it creates an object pool. When this happens, it may affect performance, because several items are created for the pool.

To avoid this, you can manually create your own object pools in a scene with a specified number of starting units. The pool manager will automatically find and use them, avoiding that first-time glitch.

To create an object pool:

  1. Create a new game object in the scene and add an Object Pool component to it.

  2. Drag a prefab into the Prefab property in the inspector.

  3. Set the number of default units in the inspector. This is how many will be created at the start.

This pool will be used by the Pool Manager when something needs to spawn the prefab.

PreviousFloating OriginNextMenus

Last updated 2 years ago

Was this helpful?