Integrating TileEd into custom level editor

(Janne) #1


We recently got TileEd to be included into our level creation pipeline. All the maps in our game are loaded inside the same scene via custom level save / load functions that work inside Unity Editor (not play mode). The plan is to use the mapdata ident to identify which TileEd data goes into the level that is being loaded. The API calls we would need for the implementation are:

  • Save data of current map ident (this is done automatically in accordance with the scene file if I understand correctly?)
  • Load data of certain map ident into TileEd (regardless of the current scene)
  • Create new ident and clear the map data to start making a new map

At runtime the plan is to load the objects placed by TileEd the same way we load all our other objects, via custom script that saves the object type ID and transform. We can save this data the same way we do for other objects, from our level save function. This part we already have working no problem. So the above API access would only be used for editor loading where we prefer to use the TileEd format to retain the map editing capabilities.

Any hints to how we could best achieve this? In addition I think there are stuff like disabling any existing OnSceneLoad logic TileEd might have to load the correct map data since we always use the same scene. Any other caveats?

I haven’t begun digging much through the bundled source code, I was hoping to make it an example here so others could take a hint at how to easily include TileEd into similar projects.

(Leslie Young) #2

Not quite understanding what you are asking about but let me just explain the “runtime side” of TileEd.

TileEd does nothing at runtime. It is used to place objects at edit time. Object you could have manually placed.

It uses the TileEdMap and plyIdent components to add a minimal level of identity to the objects placed in the scene. This is so it can build a cache faster when you edit the maps.

Of course you could use these at runtime if you want for whatever reason. Especially if you also load the map data at runtime. For example the map assets in Assets\projectData\TileEd\Maps. The TileEd map and tile set assets where separated into a runtime DLL for this reason.

You will find the source for the TileEd runtime DLL in \Assets\plyoung\TileEd\packages. Again, these are just asset/ data definitions. TileEd has no runtime API.

Here is what the components look like I mentioned above.

namespace plyLib
	[SelectionBase, AddComponentMenu(""), HelpURL("")]
	public class TileEdMap : MonoBehaviour
		[HideInInspector] public string ident;

	public class plyIdent : MonoBehaviour
		[HideInInspector] public int i_ident;
		[HideInInspector] public string s_ident;

		protected void Reset()
			this.hideFlags = HideFlags.HideInInspector;

(Janne) #3

Hello and thanks for replying.

Sorry for not being clear. To clarify, we don’t require anything of TileEd on runtime.

This is only about being able to control what and when TileEd loads into the map data in the editor.

In the documentation you’ve provided on this site I see that TileEd loads the map data when you select it in hierarchy. We would like to be able to specify which map data file it is currently working on because we work on all of our levels in the same scene. I assume there must be a function for loading a given ident but I don’t see it exposed in the API?

I tried manually changing the ident field in the Map section of inspector but it seems when I press “Recreate” it still uses the original ident instead of the new ident I typed in. Is the TileEdMap.ident string “read-only” as well or would changing the string in code cause TileEd to load the data from the new file when I use Recreate? And is there an exposed function for Recreate I could use in my editor scripts?

(Janne) #4

So far I’m only scratching the surface at getting the functionality. Remember all of this is Unity editor.

I am getting inconsistent results by assigning TileEd.TileEd.Instance.mapObj.ident and in editor. When I use recreate and/or scene load after this modification I sometimes still get the old map data from previous ident. I think the mapCaching is interfering, but setting mapCache to null throws exceptions as well. So now my guess is to try a coroutine to set the ident, null the mapCache and trigger TileEd caching process (that is completely undocumented as far as I can see…) and after caching is done see if Recreate uses the map data from the right ident… Can you give me any clue on how to implement the TileEd loading process?

It’s really frustrating trying to build a custom map loading routine for TileEd in the editor by trial and error. I still have no clue how to save or trigger TileEd saving the map file when I want. It only seems to happen on scene save which is backwards in our case. I haven’t found any saving functions in plyEdUtils which is what the TileEd map loading uses. How does TileEd save the map file and how can I control when to save?

(Leslie Young) #5

am getting inconsistent results by assigning TileEd.TileEd.Instance.mapObj.ident and in editor

You can have more than one TileEd map in the hierarchy. The map being edited is the one selected in the hierarchy (the one who’s inspector is showing).

Can you give me any clue on how to implement the TileEd loading process?

You click on on a TileEd Map GameObject in the Hierarchy. The inspector for the TileEdMap components becomes active. TileEd (the custom editor inspector for TileEdMap) goes look for the correct asset file and loads it. The Inspector UI and Scene view are rendered in sucha way that you can edit the scene with the help of TileEd.

How does TileEd save the map file and how can I control when to save

It marks the asset file and scene dirty when you place a tile. It gets saved when Unity decide to do so.

(Janne) #6

I know how to use TileEd. I’m working on making this work programmatically (C# code) so that we could actually use TileEd in our existing project.

I need to be able to save the map while even when I don’t save the Unity scene. I need to make these 2 functions in order to get it working:

//loads data into the only TileEd Map GameObject in the Hierarchy
public void LoadTileEdMap(string MapIdent){

//saves data into the specific file
public void SaveTileEdMap(string MapIdent){

When you are providing a tile-based level editor it’s not unreasonable to assume these functions should be provided for the users with the addon.

EDIT: Thanks for the package though, I hope it helps me further with this.

(Leslie Young) #7

LoadTileEdMap/ SaveTileEdMap

Ye, that is now how this tool works. The asset file is only really there to help the auto-tiles tool determine what is in the scene without having to build a cache first (slow process) by running through all tile objects in scene. It also helps when you did a combine and want to return to the non-combined version of the map.