Skip to main content

Methods

Simulate can be implemented to use the Editor update event to do something. In TpAnimatedTile and TpFlexAnimatedTile it’s used to show an animation preview. It's unlikely that you'd need to implement this yourself if you inherit from classes that already implement this feature.

TilePlusBase has two other methods that you probably want to override:

  • StartUp
  • GetTileData
  • ResetState.

Overriding StartUp must be done a specific way: a simple example can be found in TpAnimatedTile. Basically, you must call the base method as usual, but pay attention to the return value: if it’s false your override must return false without doing anything else:

//this has to be the first thing to do.
if (!base.StartUp(position, tilemap, gameObject))
	return false;

It would be an extremely bad idea to change any code in the Startup method in TilePlusBase. Worse than being eaten by the Sarlacc on Tatooine or looking into the atomic furnaces of the Forbidden Planet, Altair IV.

GetTileData is probably the most complicated override, aside from being sure to call the base class or duplicating its code, examine some of the examples for guidance. But it’s obviously extremely specific to what you’re trying to do. Be sure to use the tilemapIsPalette field to exit the method after the base call if tilemapIsPalette is true. Otherwise, your tile might animate in the Palette window. GetTileAnimationData code should also test tilemapIsPalette. See TpFlexAnimatedTile for examples.

ResetState is used in-editor when using the Bundle Tilemaps menu command or the TilePlus Bundler command in the hierarchy window’s context menu.

It’s also used when you pick and re-paint a clone TPP tile or use TpLib.CopyAndPasteTile.

It's also used at Runtime: for example, when using the Layout system, the actual TilePlus tile instances are held within the BundleRuntime in acertain cache. When the tile is loaded onto a Tilemap, changed fields are actually occurring in the cached tiles.

When the TilePlus tile is unloaded from a Tilemap (when the camera moves to a position where that tile isn't visible) it's deleted from the map but the instance remains in the cache. The next time it's loaded any changed variables will be exactly the same.

During the unload process ResetState is called with a request for a 'local state' reset. All that means is that you should reset any values that you need to.cirumstances.

For example, if you have some boolean field that you set true after StartUp to indicate that you've initialized something then that should be reset or the field will remain true.

The implementation must reset fields so that stale data isn’t persisted. Be sure to call the base method. This is a misleadingly simple method that you need to think about carefully. You don’t want to reset all fields, or you’ll be undoing changes made to your TPT tile. See the various implementations for examples.

If you're using the Layout system andexclusively, you runshould know that TPT tiles are cloned every time they're placed. Hence, there are no 'stale' cached tiles when using the Layout system.

If you into unexpected tile code behaviour this is a good place to look first.