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:
- accept challenge
- cancel project
- 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?
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: http://developer.valvesoftware.com/wiki/L4D2_Level_Design/VMF_Instances
I hope you give instances a try, share them and abandon prefabs.
Thank you for reading!