Team Fortress 2

Team Fortress 2

Not enough ratings
How to use instances to make tf2 mapmaking easier
By Tiny Desk Engineer
This is a guide on how to use func_instance entities in Hammer to make mapmaking easier, faster, and, I cannot stress this enough: Less ♥♥♥♥♥♥♥ annoying

This is probably gonna be mostly a community made guide, as I have a limited understanding of this, as I have only started making instances, but I couldn't find any other guides for this kind of thing, so, if you know something that isn't mentioned below, please tell me about it, and if it fits this guide, I will add it if I find time to.
   
Award
Favorite
Favorited
Unfavorite
What is a func_instance?
A func_instance is an entity in the Source engine that is used to save certain complex objects, and reuse them easily among several maps, used officially only in Portal 2, but they do work in other Source games (the only one I'm sure of actually works is TF2, which is lucky, because it's the one that has caused me the most trouble, especially with figuring out how gamemodes work.)

If you change the instance file, all of the instances that use it will change to match the instance, but you will of course have to re-compile the maps that use it for them to work, and if they are on the workshop, you will have to re-upload them.

Instances are useful for more efficiently making maps that use things that either take too long to make or are too annoying to make so much of (eg. large groups of logic used for gamemodes, custom variations or not)
How to make instances?
First, before you start making your first custom instance, you should add a few new folders to store the instances and categorize them

the first folder you should make is a folder with the name "instances". this will store all of the sub-folders that will categorize the instance files.

some useful sub-categories are:
"decor" for decorational objects like crate clusters and maybe some custom lights
"gamemodes" for storing subfolders for every gamemode in TF2 to store gamemode-specific objects
"generalGameplay" for general gameplay objects like spawnroom objects and even maybe spawnrooms themselves, containing the separate spawnroom instances
"miscellaneous" or just "misc" for things that can't really be categorized

Now that you have the instance folders set up, you can now start making your own custom instances

Go into Hammer, then create a new map, put whatever you want in it, then save it in one of the folders you just created a few seconds/minutes ago.

You now know how to make basic instances!

...Hopefully.
How to use custom instances?
Ok. If you finished the last part of this guide, you should have something you can use in an instance

Now, something that can be really useful is having a map specifically for you to test new or edited instances to make sure if they work before you actually try and use them only to find out they actually don't work.

Ok. If this is your first time using instances in the TF2 Hammer editor, you will probably want to change the instance path in the gameinfo.txt file. as long as you change only that, it should be fine.

First you need to find the gameinfo.txt file.

The file path for me is:

E:\Program Files\Steam\steamapps\common\team fortress 2\tf

The gameinfo.txt file should be somewhere in the tf folder.

This is just my filepath, it might be different for you. try looking in different drives for the Program Files folder.

Then you need to open the gameinfo.txt file in some kind of text editor, like Notepad.

You then need to find the path to your tf2 mapsrc folder, the folder that stores the maps you've made in Hammer, and replace the instances filepath in the gameinfo.txt file with it.

Once your done, it should look something like this:

E:\Program Files\Steam\steamapps\sourcesdk_content\tf\mapsrc.

Then instances should be easy to use, as you can just fin the instance vmf file you want, click on it, and it will fill in the vmf filename in the func_instance.

It should also hopefully be easier to make larger instances, as you can use instances in instances.
Extra utility in func_instance_parms entities
The func_instance_parms entity is an entity used in instances to add easily editable parameters that allows you to change certain things about it to make it different from the other instances of the same type.

How you use the func_instance_parms entity in your instances is, in the instance vmf file, replace certain properties of entities in the instance with variable names, for example, if you have a resupply locker instance that you want to have both teams in one single instance, replace the "Team" setting in the func_regenerate with something like "$team" instead of just putting in a team for the resupply. The "$" symbol is necessary, but you can name the variable whatever you want.

Then, if you add a func_instance_parms entity to the instance, you can then add parameters to the instance.

There are three boxes you need to fill in for each variable you add: Variable, Value, and Default.

The variable box is what you use to choose what variable in this instance you want to be able to change, with the same example of the resupply locker from earlier, you can put $team in this text box.

The value drop-down menu is used for specifying what variable type this will use, for example, "integer" is a number without decimal places, "float" is a floating point number with decimal places, and you can even allow you to change the instance files of func_instance entities inside of that instance!
Examples: 5, 2.56, resupply.vmf

The default box should be pretty easy to understand. It's the default value for that variable.
Examples: $time integer 60, $team integer 2
Things you shouldn't do
This section will list several things you shouldn't do with instances.

Have an instance use itself, or another map that uses it, as that would cause an infinite loop which would never stop, which would, if somehow not cause errors, will crash the hammer editor, and worse, potentially crash your entire computer.
5 Comments
BezaoBuilder 24 Aug, 2020 @ 11:16am 
Just checked, func_instance_io_proxy is avaliable in all Source games since Alien Swarm, and Alien Swarm was released in 2010, before TF2, that was released in 2007.
Tiny Desk Engineer  [author] 24 Aug, 2020 @ 10:15am 
I actually don't think the proxy entity is in the tf2 hammer editor, I tried to find it, but when I searched "proxy" in the list of entities, I don't exactly remember what I got, but I don't remember seeing that entity in the list.
BezaoBuilder 17 Aug, 2020 @ 9:19am 
Entities inside instances can receive and send outputs/inputs, so if you have a spawnroom door instance, you could make it receive an input to open it, close it, or if you have a spawnroom entity, you could make inputs for it like "disable" or "give this spawnroom to red/blu". Check this site: https://developer.valvesoftware.com/wiki/Func_instance_io_proxy It is from Valve.

Instances are extremely useful for making maps, because sometimes you have something that you want to use multiple times, and if you update the instance file, to fix a bug, for example, it will update in every map that uses that instance.

Sorry for posting twice, but Steam would not let me write such a long comment.
BezaoBuilder 17 Aug, 2020 @ 9:18am 
Also, some extra things:
Note: I learned them while making maps for Portal 2, but they should be the same in TF2
The instances folder has to be at the location of your map file.
Your map must be saved before it can use instances.
If instances are glitched for some reason, just save the map.
If doing instances inside instances, make sure to never make an instance contain itself, or another map that has it on.
Tiny Desk Engineer  [author] 16 Aug, 2020 @ 3:01pm 
I probably took around an hour and thirty minutes on this guide, and it isn't even as good as it could be. I will check the comments here and will update it with comments that fit it.