informa
1 MIN READ
Featured Blog

Handling Bullet Holes in Unity

A short post about maintaining regularly spawned GameObjects in Unity5.

This was originally published on https://mutinyproductions.wordpress.com/. Our team is working on a FPS designed for short play sessions.

In the current project we are working on (Dawnbreak) we are intending to target a large range of platforms on release. This is primarily to gain experience on these platforms, and to maximise our player base.

Designing a game that can handle different platforms requires some thought to be how we handle textures in game. Our game requires guns and guns create bullet holes. Each of these bullet holes is a small texture painted on to the environment at run time. Over time, all those bullet holes add up to a huge amount of memory for something that really only added a moment of impact.

To solve this I created  Object Manager that cleans up and removes bullet holes when too many get created, allowing for players to continue to have an impact on the environment while not sacrificing too many resources.

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class ObjectManagement : MonoBehaviour {

    public int MaxNumberOfObjects = 100;
    List< GameObject> ObjectList = new List< GameObject>();

    void ManageObjects()
    {
        if(ObjectList.Count > MaxNumberOfObjects)
        {
            GameObject tempObj = ObjectList[0];
            ObjectList.RemoveAt(0);
            Destroy (tempObj);
        }
    }

    public void AddObject(GameObject _object)
    {
        ObjectList.Add(_object);
        ManageObjects();
    }
}

The manager is inherently simple to implement and use. A developer can set the maximum number of objects in the editor or set this in run time as a way to gain resources if a game gets too heavy. Call

AddObject(_object)

and pass the GameObject wishing to be managed as a parameter. An easy way to manage anything in your scene that gets spawned with regularity!

Liam Simmons ~Software Engineer at Mutiny Productions. Check us out on Twitter @MutinyProds

Any advice/criticisms most definately welcome!

Latest Jobs

Sucker Punch Productions

Hybrid (Bellevue, WA, USA)
11.30.23
Senior Programmer

The Pyramid Watch

Remote
11.22.23
Game Designer (RTS/MOBA)

Sucker Punch Productions

Hybrid (Bellevue, WA, USA)
11.30.23
Senior Technical Combat Designer

Digital Extremes

Remote
11.13.23
Lead AI Programmer
More Jobs   

CONNECT WITH US

Explore the
Advertise with
Follow us

Game Developer Job Board

Game Developer

@gamedevdotcom

Explore the

Game Developer Job Board

Browse open positions across the game industry or recruit new talent for your studio

Browse
Advertise with

Game Developer

Engage game professionals and drive sales using an array of Game Developer media solutions to meet your objectives.

Learn More
Follow us

@gamedevdotcom

Follow us @gamedevdotcom to stay up-to-date with the latest news & insider information about events & more