0 votes

I'd like to add an existing tileset to a tilemap in code. How would I go about doing this? I've tried preload() but I don't see any way to create an instance of the tileset so I can't refer to it later. This is my code right now, which doesn't seem to do anything.

tilemap.tile_set = preload("res://scenes/tilesets/tileset_001.tres")
asked Jun 11 in Engine by Socrates (547 points)

Oh, thank you, it's working now. My error was elsewhere (didn't have the underscore in front of my _ready() function :( )

1 Answer

0 votes
Best answer

The code you used should basically do that, I don't understand what else you really expect...
Contrary to nodes, a TileSet is a resource, so there is no need to make an instance of it. Loading it already give you the instance, and if it's already loaded then Godot will just give you the same instance without reloading it.

answered Jun 11 by Zylann (14,838 points)
selected Jun 11 by Socrates
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.