← Back to all addons

Custom Command: "Set Tile"

Posted by Gyvr on Apr 9, 2025 at 6:10 PM

GameplayFeature3.0 Verified
💡 5

Sometimes you might want a command to modify a tile (for instance, to show a bridge over water, or to change an element of the decor, without having to make a GameObject for it). Add this script anywhere in your project to get a new “Set Tile” command

using System;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.Tilemaps;

namespace Gyvr.Mythril2D
{
    [Serializable]
    public class SetTile : ICommand
    {
        [SerializeField] private Tile m_tile;
        [SerializeField] private Tilemap m_tilemap;
        [SerializeField] private Vector3Int m_position;

        public Task Execute()
        {
            m_tilemap.SetTile(m_position, m_tile);
            return Task.CompletedTask;
        }
    }
}

💬 Comments (6)

BellBlitzKing Apr 10, 2025 at 12:00 AM
🤔 I wonder if this can be used so players can build on the world? Like tile placement in-game as a mechanic? Like placing items & scenery inside their house 🕵️♀️ to make it their own
Gyvr Apr 10, 2025 at 12:01 AM
Yeah for sure
Gyvr Apr 10, 2025 at 12:01 AM
Probably better to have a dedicated system tho
💯 2
Gyvr Apr 10, 2025 at 12:01 AM
Commands aren’t going to be super helpful here
BellBlitzKing Apr 10, 2025 at 12:02 AM
Mythril 4.0 idea for sure. I imagine you’d need a Home Inventory separate from the Player Inventory too. Or if tile placements are permanent, would need a save system for those in-game newly placed tiles too.
👌 2
BellBlitzKing Apr 10, 2025 at 12:04 AM
Mythril Minecraft & Mythril Valley for 2029 😅 Take my money!!
😆 2

Want to continue the conversation?