[Released] Prefab Atlas - Easiest pooling solution

Store link

features:

  • Easy to setup, easy to use pooling solution, simplicity is key.
  • Allows you to choose what to load on a scene by scene basis.
  • Manage preloading of prefabs to avoid hiccups during gameplay.
  • Manage how many elements a pool can contain, so you choose the perfect balance between memory and efficiency.
  • Manage how many elements of a type can exist period, allows you to get all the control over allocations in your game.
  • Organization, dont bother creating prefabs the old way anymore, let this tool organize them for you, automatically creates a prefab from a game object in the scene when drag and dropping on the group (see the tutorials on how to add elements to a group) and puts them in a folder created for you using the groups’s name. You dont have to look for the prefabs as well, use the custom window to select prefabs that are inside any group.
  • Lightning fast performance and self managed, you really dont have to worry about keeping any kind of reference to any prefab, any instance of any pool, anything, just setup the atlas and use. The spawning is as fast as it can get.
  • Dedicated development with over three years of improvements and counting. I hear the feedback of everyone and take it in consideration when adding/improving features, I always answer within 48 hours and you can count on my continuous support.

BASIC USAGE TUTORIAL

This tutorial seeks to illustrate how to setup step by step the Prefab Atlas and how to use it in code.

Open the Prefab Atlas Window by clicking on Tools->Prefab Atlas Editor:

By doing this, the prefab atlas will check if you have a prefab atlas object already created within your Assets folder, if it cant find one it will create one. You should see this window:


The window is divided in 3 sections (Groups, Prefabs, Scene Object Setup), this window reads your Scene Object, if it cant find one then it will display the option to create an Scene Object:


Click the Create Scene Object button and the option will hide. After doing this we require a new Group, click on the plus sign on the Groups section:


This will create a new Group with the default name “GroupName”, you can click on this group name to change it (Note: Groups need to start with a letter or code friendly symbol such as underscore “_”, this is because the groups get parsed into C#).

Now we only need to add an element to our new group, there are two ways of doing this, the first one is the classic way, drag and drop a prefab that was created previously:

But in recent updates, a new way of adding prefabs was introduced, and it is also the recommended way, simply drag and drop a GameObject in the hierarchy to automatically create a prefab from it and add it to the Group:

All the elements inside the group can be seen within the Scene object setup, where you can modify their Preloads, Capacity and Max Instance, a bit of explanation on each element:

Preload: The amount of instances the pool will create once the game starts, this is useful to avoid making instances during gameplay which could cause hiccups.

Capacity: The amount of elements a pool can hold at any given moment, this is useful to limit how much memory you want to actually hold, say you create 1000 elements freshly from your pool, but you only want to keep a 100, so you set your capacity to this number and once 100 go back in, the pool will stop accepting new elements and will destroy them, freeing up memory. -1 will disable this feature.

Max instance: Think of this a rule of how many can be alive in the pool or out of it, combined, extremely useful for particle effects or sound related elements. Only want 400 snow flakes at all times? set this to 400.

You will also notice a “DEFAULT VALUES” section in all groups, in this section you can massively apply the defaults to all the elements in the group, this is for convenience to quickly setup the values in mass, just press the “apply defaults” button.

Finally to conclude the setup of our Prefab Atlas, we require to commit our changes, press the button on the top right corner of the window:

Your project will reload if there were any changes, this is because the prefab atlas when you click commit it will parse the information from the editor to C# code that will allow you to use the prefab atlas in code and in the editor. That concludes the basic setup, you can create more groups, add more prefabs to the groups, and tweak your Scene Object setup.

Now onto the code usage:

Fire up your favorite IDE and create a new Monobehaviour class, I will name mine PAtlasExample:


We will first use the most straight forward way to use the prefab atlas, on the OnEnable function we will do a direct call and create an instance of the prefab we added to the atlas, remember my group was called “GroupName” and the prefab was called “Cube”:


This is doing the following:

  • “PrefabAtlas.Spawn(GroupNameTag.Cube, new Vector3(0.0f, 0.0f, 0.0f));” gets the element from the pool with Tag “Cube” and creates an instance of it at position 0,0,0.

Note that there are several options for the “Spawn” function, you can specify its position, rotation, or none of them, if you dont specify anything it will create it at position 0 with the rotation also at 0 in all angles. Thats the most basic way to use the prefab atlas in code, now we will take a look at the PAT values:

The biggest difference here is that the code doesnt need to know before hand what it is creating, because the PAT values (Prefab Atlas Tag) are to be set within the editor. this makes it very handy when creating versatile game objects, for example, wave spawners in a tower defense game, or a bullet changing gun, or even different types of particles/sounds, the PAT is one of the features that makes the prefab atlas very versatile. Lets take a look at it in the inspector:

The PAT value (SpawnThis) is represented in two parts, the first one being the group, you can select any group inside the prefab atlas, secondly we have the ID of the prefab that only appears when a group is selected, this list will only display elements inside the group selected.


This feature also allows for some very nice organization (much better than dragging and dropping a prefab onto a public gameobject field). Once you have setup the PAT you will be able to spawn any prefab from this script.

Now lets take a look at how to return things to the pool in code. it is very simple and it doesnt create any intrusive or special calls, the only thing you need to do is “deactivate” your game object:


What the pooled object does is listen to when the prefab gets deactivated, and returns it to the pool. Simple as that, you can even destroy the object if you wish, the Prefab Atlas will handle the instance being destroyed as well.

If you would prefer some videos, here you go (I am terribly sorry for my accent):

Basic setup:

Examples of usage:

Pending review: PlayMaker Integration, here is a quick video that shows how to use it:

The Playmaker extension is live in the Asset Store now: LINK

The prefab atlas is on sale Today, pick up your copy! and if you have any questions prior to buying or after buying please dont hesitate in posting here!

Have a link: Link

REMOTE POOLS?
Does Prefab Atlas support any remote prefab pool mechanism? For example client app wants to load objects from a remote Prefab Atlas file or a Unity AssetBundle file that is located on a remote server. If remoting is not supported yet is there any plans to implement it later on? The asset looks so cool that I may buy it anyway :slight_smile:

Hey Masaco,
As of now, the prefab atlas only works locally, I can definitively look into the feature, I could make the “prefab scene object” to load the prefab atlas from a server.

Thanks for the idea, I will investigate :slight_smile:

1 Like

hi here i try make list of one group for loading by int ? for exemple

any way to clear or reduce to big pool ? if it’s serve to somethink’s

about name duplicate it’s possible to use id ? i’am slaking on that’s lol

Hey Kilik, I am not sure I understood what you meant, but groups need to be uniquely named in order to compile (this i because it creates code for you).

As of using the same prefabs in differents groups, it is possible and it will not give you any troubles, all the elements are actually hash values (ints) that are created when doing a commit.

If I was way of on what you meant you could type it in your native language and I will try my best to traduce from there.

sure and for the list for exemple

when need the item 3 on one group

Do you mean you want to add IDS into a list to be configurable in the inspector?
If this is the case, you can use a PAT value inside a public or serializablefield list, for example:

    public List<PAT> IDS;

This will show a list in any monobehaviour for you to play with.

Hope it helps!

Yes it’s somethink’s like that’s
in fake i think’s if this list can already created like
for exemple

public List IDS =new pat group1 object1 , group1 object2 … etc ;

Man, I’m struggling here to follow how to create something in the pool via script.

The video for it is REALLY hard to read and follow. I’ve got it set to 1080 and the text is barely visible and it blasts through the stuff I need to see. And it looks like you cut off a library that I need at the top of the script.

Is there any way you could do a script tutorial that isn’t a video? Like maybe a series of screen shots and code exerts? It would be a good way to bump your asset on the forum :roll_eyes:.

Or at least do another video that is easier to follow?

Thats an excellent idea! I have edited the first post and it now contains a full basic usage of the Prefab Atlas, if this is not clear dont hesitate in letting me know, I will try my very best to help you utilize this tool :slight_smile:

Version 1.0.3 has been accepted and is now live in the Unity asset store.

Changes:

  • In some cases if the project contains many folders the prefab atlas used to take a longer time to load its window, this will no longer be the case.

  • When committing a group without prefabs, the tool used to create an empty switch block which would throw a warning. now the atlas will no longer create the empty switch.

  • Editor prefabs integrity was heavily improved, the tool used to check every tick for changes, now it handles changes differently.

A new price has been set as well, after comparing the tool with other similar solutions.

I wanted to thank everyone who has given me feedback, it helps me to better serve everyone who uses the Prefab Atlas. If you have any questions or any feedback, please don’t hesitate in asking.

Hey there, really nice tool I must say. Thanks and well done!

However, I’ve got a little problem there - I wish if there was a “None” enum for every generated tags so I could do a check whether I need to spawn the prefab or not. Probably None = 0 or something
This also helps “reset” the selection in the editor too i.e. if you were selecting some tag, there is no way to clear it, right ?

Cheers,
H

@Hyldemoer The default could be None instead of simply not having any tags, I like this idea very much, the Prefab Atlas could also handle when None is passed.

Thanks for the feedback! I will definitively implement this :slight_smile:

1 Like

Cool! I look forward for the new release! Cheers :slight_smile:

The Unity Asset store team are working very fast! Version 1.0.4 is out right now, it implements the “None” tag as the default value in all the groups.

Also, PAT values are now properly cached just like the normal tags were, thanks to this there are no more look ups besides the initial one. The performance gain is pretty awesome while still allowing the versatile usage of the PAT values. (I would dare to say it is as fast as it can get in terms of queries :slight_smile: )

And lastly, Unity has been kind of odd when re exporting packages as of late, it has happened to me that instead of overriding the files inside the folders it simply deletes and replaces the entire folder or parts of it, this could potentially delete your PrefabAtlas.prefab and PrefabAtlasExtension.cs files, for safety before updating your PrefabAtlas make sure to backup these 2 files as they contain all your custom information(located in PrefabAtlas->Components), if something goes wrong just delete the entire folder (PrefabAtlas) and re export the package, then re add these 2 files.

Thank you all for your feedback and for supporting this tool.

Version 1.1.0 is live in the store.

Changelog:

  • Scene objects now have default values, before it was possible that if you didn’t update your scene objects in scene “A” (by having the Prefab Atlas window open while in that scene) and added more prefabs to the atlas while in scene “B” when running the game and navigating to scene “A” the atlas would have thrown an exception due to not having the newest added prefabs configured, this is now fixed and you can safely add prefabs to the atlas while not updating all the scene objects, if they don’t find an entry they will use their default values (preload 0, max instance -1, capacity -1) (is still recommended that you do so, but do it at your own leisure).

  • Creating prefabs out of hierarchy game objects by dragging and dropping in the groups. Before, the atlas wouldn’t accept anything that wasn’t a prefab. now it will automatically create a prefab out of any hierarchy game object you give, example:

As you can see, the element turns into a prefab, and you can use the prefabs tabs to quickly select it to be shown on the inspector, still, all the prefabs generated by the Prefab Atlas are sent to “Assets/PA_GeneratedPrefabs”:

As always, back up your projects before updating, and if you have any feedback don’t hesitate in letting me know.

hi,
how would you spawn a random prefab, only once, then remove it from pool, so the next call picks another prefab?