0
\$\begingroup\$

I am trying to make some kind of tileset texture replacer using an editor window.

First, I try to save all tile and texture names in let say "scenename.ctss" (ctss stand for "custom tilemap save system"), and then load but with different textures. ut

The problem is that I can't find anywhere on the internet on how we can create a TileBase instance, and then apply texture to it.

I was expecting creating TileBase would be as simple as this line of code:

TileBase tileBase = new TileBase();

but i get this error message:

CS0144: Cannot create an instance of the abstract type or interface 'TileBase'

Is there a way so that we can create our own custom TileBase in Unity?

\$\endgroup\$
8
  • \$\begingroup\$ Did you mean to use Tile.CreateInstance instead? \$\endgroup\$
    – DMGregory
    Aug 4 '21 at 17:25
  • \$\begingroup\$ how do i write it in my code?, i was trying TileBase tileBase = Tile.CreateInstance<TileBase>(); but i got this error Can not create instance of abstract class 'TileBase'. \$\endgroup\$ Aug 4 '21 at 17:35
  • \$\begingroup\$ So you read that message, said to yourself "Oh right, in C#, an abstract class is one that can't be instantiated. I meant to use the non-abstract Tile class instead" right? \$\endgroup\$
    – DMGregory
    Aug 4 '21 at 17:50
  • \$\begingroup\$ ah i see, but if that the case (sorry i change the question a little bit here) how do we place tile using tilemap.SetTile(position, tileBase), or, is there any other method that i misssed? \$\endgroup\$ Aug 4 '21 at 18:02
  • 1
    \$\begingroup\$ Want to post your solution as an Answer below? You may also want to work with some beginner C# tutorials to make sure you understand fundamentals of the language like this. \$\endgroup\$
    – DMGregory
    Aug 4 '21 at 18:22
0
\$\begingroup\$

What this error message is telling you is that TileBase is an abstract class. It's just the foundation ("Base") to use when building custom tile classes that you might want to instantiate. But you can't instantiate the base itself — it's incomplete on its own.

A concrete implementation of the TileBase is given by the Tile class, which you can create as:

Tile myTile = Tile.CreateInstance<Tile>();

The Tile class inherits from TileBase, so it can be used as an argument anywhere a function parameter asks for a TileBase. Tile is just a specialized flavour of TileBase (and a fairly general-purpose one that's fit for the most common use cases).

So for example, assigning this tile to a specific spot on your tilemap could be accomplished by:

tilemap.SetTile(position, myTile);
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .