Adding tiles in runtime to a tileset

I have a TileMapLayer “OreTiles” with a TileSet “TileSet”. I have loaded an image of a tile I would like to add to the set in code. Is there a way I can add this image as a tile in the TileSet as part of the code? I can barely find anything useful online. Thank you.

I believe you can’t do that. But you can add a new TileSetSource to existing TileSet via code. You could even create a new TileSet. Code below is not from a real world example but just to point you to the classes you should be looking into.

var tileset : TileSet = TileSet.new()
var tileset_source : TileSetAtlasSource = TileSetAtlasSource.new()
# todo: set texture and props to tileset_source
var atlas_source_id = tileset.add_source(tileset_source)

So how do you set the texture?

Sorry for the late reply. The texture will load in a temporary text TextureRect, but will not load in the tile source. However, the tile source is very clearly getting created and placed. Is there any other properties I need to set to work properly?