Godot Object Pool

An asset by brandonlamb
The page banner background of a mountain and forest
Godot Object Pool hero image

Quick Information

0 ratings
Godot Object Pool icon image
brandonlamb
Godot Object Pool

Godot object pool. Used to instantiate a pool of objects using a user-defined pool size, PackedScene, and prefix. Some convenience methods exposed allowing a pool.get_next_dead() to fetch the next available object from the pool.

Supported Engine Version
3.0
Version String
1.0.8
License Version
MIT
Support Level
community
Modified Date
7 years ago
Git URL
Issue URL

godot-object pool

An object pool for Godot.

Usage example:

PlayerController.gd

const Pool = preload("res://addons/godot-object-pool/pool.gd")
const GreenBullet = preload("res://com/example/bullets/green_bullet.tscn")

const BULLET_POOL_SIZE = 60
const BULLET_POOL_PREFIX = "bullet"

onready var bullets = get_node("bullets")
onready var player = get_node("player")
onready var pool = Pool.new(BULLET_POOL_SIZE, BULLET_POOL_PREFIX, GreenBullet)

func _ready():
    # Attach pool of objects to the bullets node
    pool.add_to_node(bullets)

    # Attach the "on_pool_killed" method to the pool's "killed" signal
    pool.connect("killed", self, "_on_pool_killed")

    set_process_input(true)

func _input(event):
    if event.is_action_pressed("ui_select"):
        var bullet = pool.get_first_dead()
        if bullet: bullet.shoot(player.get_node("weapon_position"), player)

func _on_pool_killed(target):
    target.hide()
    print("Currently %d objects alive in pool" % pool.get_alive_count())
    print("Currently %d objects dead in pool" % pool.get_dead_count())

Godot object pool. Used to instantiate a pool of objects using a user-defined pool size, PackedScene, and prefix. Some convenience methods exposed allowing a pool.get_next_dead() to fetch the next available object from the pool.

Reviews

0 ratings

Your Rating

Headline must be at least 3 characters but not more than 50
Review must be at least 5 characters but not more than 500
Please sign in to add a review

Quick Information

0 ratings
Godot Object Pool icon image
brandonlamb
Godot Object Pool

Godot object pool. Used to instantiate a pool of objects using a user-defined pool size, PackedScene, and prefix. Some convenience methods exposed allowing a pool.get_next_dead() to fetch the next available object from the pool.

Supported Engine Version
3.0
Version String
1.0.8
License Version
MIT
Support Level
community
Modified Date
7 years ago
Git URL
Issue URL

Open Source

Released under the AGPLv3 license

Plug and Play

Browse assets directly from Godot

Community Driven

Created by developers for developers