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

Xbox Game Studios

Redmond, Washington
10.5.22
Technical Lighting Artist

Innogames

Hamburg, Germany
10.5.22
Game Designer - Elvenar

Six Foot

Houston, TX
10.3.22
Six Foot Director, Player Relations

Hometopia Inc.

Remote
10.7.22
Lead Engineer
More Jobs   

CONNECT WITH US

Explore the
Subscribe to
Follow us

Game Developer Job Board

Game Developer Newsletter

@gamedevdotcom

Explore the

Game Developer Job Board

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

Browse
Subscribe to

Game Developer Newsletter

Get daily Game Developer top stories every morning straight into your inbox

Subscribe
Follow us

@gamedevdotcom

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