Instances - What are they?! Why use them?!

It saddens me to see that some people still use prefabs when there are instances. When I search for “func_instance” in the SPUF I get nine threads as a result. That leads me to the conclusion that nobody uses them because nobody knows about them. Let me tell you about the numerous advantages of instances.

Imagine this common situation: You made a map and you’re about to place 50,000 doors. Each one consists of multiple entities so it’ll look really fancy. You now have three options:

  1. accept challenge
  2. cancel project
  3. use func_instance

Without instances you would have to copy and paste the door each time and rename every entity and fix every output and parentname. Let’s say you got balls of aluminum oxide and really do it, what’ll you do when you find out you made a mistake at the first door and have to correct each one? That would have been no problem, if you had used func_instance!


Func_instance is a point entity which loads and places VMF files. Basically a map within a map. It’s like a prefab that stays a prefab. One of it’s biggest advantages is that it automatically gives every target- and parentname of the entities inside the VMF a pre- or postfix (or not, if you turn it off). You can enter your own name or let the VBSP create one for your.

So in our case, you take the first door, copy it, paste it in a new map, save the VMF, place a func_instance, select the VMF and copy and paste the instance around your map. If you make a mistake, simply open the VMF and correct it. All instances will be updated.
Another advantage is that you can work more convenient with more simple names: “doubledoor_a_left_model123_wtf” turns into “door”. Once you compile it VBSP will fuck the names up for you when you don’t need to work with them anymore (unless you use “ent_fire” a lot).
Instances do only appear in Hammer. When you compile the map, it’ll disappear, it’s no existing entity. That’s why you can’t see any instances in decompiled maps.


When you try it out with doors or something else that uses directions, you’ll notice that the directions stay the same when you rotate the instance (edit: Does not happen anymore in Alien Swarm and newer games). That is a little disadvantage (that’ll hopefully will be fixed some day) which you can fix by using func_instance_parms. Select your door and replace the move direction with a variable ($[name]). In this case $direction would be most logical but you can give it any name you want: $WhereDoesTheDoorMove, $WhoTouchedSasha or $teGalloHalloH.
The func_instance_parms entity should automatically recognize and enter the variable into it’s properties. If not, add it by yourself. You also should choose which type of variable it is. For those who don’t know:
[li]String - any line of text (since every property turns into a line of text when you turn smart edit off, this always works)[/li][li]Integer - a number[/li][li]Boolean - true (1) or false (0)[/li][li]Studio - a model[/li][/ul]
While you can use it to fix angles, it’s mainly made for giving an instance diversity without having to create one instance for every possible combination. So you can change the model or the skin of a door, the speed of a func_movelinear, the color of a light or the number of a counter without using more than one instance. The variables will appear as properties of the func_instance:


But what if you want certain doors to be opened by a trigger from outside of the instance (from a button or something)? That’s what func_instance_io_proxy is made for! It acts as a gateway between the entities within and outside the instance. Place it in your VMF and create an output to something (like the door) to create an Input. Input to this entity to create an output. What?! All Inputs to func_instance_io_proxy will appear as outputs in func_instance and all inputs to func_instance will trigger the outputs from func_instance_io_proxy:

Protip: If you want inputs to look more organized, create a logic_relay for every input, give it a nice name and let it trigger all outputs at once:

Another way to refer to entities outside of the instance is to know what the name will sound like. If I make an output to “Relay” and I give the instance a prefix named “door”, then I can trigger a relay named “door-Relay”.
This is also of use when you have entities outside of the instance that are always different. Like this func_brush of a hidden door. It’s texture is always different and it’s parented to HD1-door. “HD1” is the name of the instance, “door” the func_door_rotating inside the instance.

So, when using func_instance in combination with func_instance_parms and func_instance_io_proxy you can pretend to create your own entities with your own properties and in- and outputs. Neat.

Useful without entities

If you think now “Ok, that’s nice, but I don’t use many entities and I can work better without those barriers.” then still func_instance is useful for you. Look at this, what looks nicer to you?[/media]

Ok, it doesn’t look nice at all, but the lower one would be nicer I guess. It’s off the grid, it feels more realistic and organic. We all should know that mapping in non-90-degree angles and off the grid is a pain in the butt. “Not a big deal”, you might say now, “I create it, make it a func_detail and rotate it”. What if you find out hours later that you made some mistakes? When you use instances, you can rotate it as often as you want, you’ll always be able to open the file and work on a grid.

I’m not sure where I read/heard it but the instance feature was also made so that multiple mappers can work on one map. It was introduced with L4D1 and I read that the levels were made out of segments (every street, building, place was an instance). So you can use instances to easily share you’re components/segments.

Compability and bugs

[li]func_instance is available in all games/engines but works only in TF2, L4D1 and newer games[/li][li]func_instance_parms is available in all games but it only works in Alien Swarm[/li][li]func_instance_io_proxy is only available in Alien Swarm and only works in Alien Swarm[/li]
(I hope Valve will make all entities available in all games soon)

[li]As written above in func_instance_parms you can choose the type of your variable, but in the func_instance you will not get the the proper menu (browse button, drop-down menu, angle button, etc) to enter the value. Also the standard value does not appear. But you can enter it yourself and it works.[/li]
[li]In Alien Swarm the browse button to choose the instance seems to work, but the chosen file will not be chosen. So you have to type the path and filename by yourself (the path is relative (I recommend to put a map and the used instances in it’s own folder)). However in the other games/engines it works fine (you must save the map first).[/li][/ul]


I myself can’t map without instances anymore. They automate and organize everything. Here you can see my collection of instances for one L4D2 campaign (all of them are gameplay elements, nothing cosmetic):

Here are examples where Valve used them in Portal 2:

More information:

I hope you give instances a try, share them and abandon prefabs.

Thank you for reading!

Hmm… Must learn this.
I’ll give it a try later today.

Question: In that image with the button. What if you make the button and the brushes underneath an instance and want to use another material? Make a new instance or change it from hammer?

Oh lol, layla is stalking me and rating my posts dumb for no reason :v:

So you either put it not in the instance or you’re limited to one texture unless there’s a way to replace the material with a variable. But I’d say leave it out.

iirc instances don’t work in source 2006-9

But they do work in L4D2 and future SDK tools.

What do you mean select the VMF and paste it. Do you mean select the contents of the VMF or the actual VMF?

Kind of weird instructions and slightly hard to understand when it comes to that first part.

wow I didn’t even know about that entity. Probably because I’m still on 2009…

But if I’m placing a door or something, how do I know how does it fit in? I mean, func_instance is just a box, so how do I know where do i put it so my door would place correctly?

It should show up in hammer as kinda yellow.

Ah I see it now! First it was just a normal box. Thanks man, this easens the making of portal 2 maps!

EDIT: It shows up as yellow only after I compile it. Any way to make it yellow before compiling?

:monocle: Thank you for this crucial information.

Did you save the map before compiling? When you don’t save it there can’t be a relative path to the VMF.

I’d be using the FUCK out of these if they worked in the Ep2 engine.

“Let’s say you got balls of aluminum oxide and really do it.”

Oh wait, I got some of those “runs to the den to get some paint”

Agreed. I tried doing this with the first Portal, it crashed vbsp on compilation :c

Think you could upload a simple example of an instanced door and how you would open/close the door in the main map? I have tried it, and cannot get it to work.

Paste special

Good news everyone! I found out that the angles do not get messed up anymore (in Alien Swarm and Portal 2) when you rotate the whole instance.

Zyx, here’s an example door (made for Portal 2):

It is a double door. There is a button on each side of the frame which opens it. And it has a trigger which will automatically open it once a player touches it.
By using the instance properties you can change the speed of the doors, the time they shall stay open and whether the automatic opening via the trigger is activated at start or not.
You can send inputs to the instance which open the door, enable or disable the buttons and turn automatic opening on or off. The instance can also fire an output when the door opens.

This + point_template with ‘Preserve entity names’ flag unchecked, and combined with env_entity_maker.

I used this to make some panels in Portal 2 - but I want to know this:
Is it possible to set up a chained delay through instancing? Like, if I want my panels to open one after the other on a single input, can I do that?
If I placed all the panels manually, I could set up the corresponding output from a button to each of them to have a delay, increasing gradually for each panel in sequence.
However, surely there’s a way to increment the delay through instancing?

EDIT: Oh, and panels which are touching eachother have their brush parts mold into one single large brush - I want it to be several little ones.