Search Unity

Is it possilbe to make a 2D building system using Tilemap?

Discussion in '2D' started by aybarsmete1, Oct 26, 2019.

  1. aybarsmete1

    aybarsmete1

    Joined:
    Oct 26, 2019
    Posts:
    43
    I was looking on Youtube for any 2D building system that uses Tilemaps until I realized there was no such thing. Is it possible and if it is, can anyone describe me how?

    Thanks
     
  2. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    Just to clarify your question, do you mean that you were looking for a system that allows you to build something on Tilemaps? Or something that concerns "buildings" and you want to do something with them on a Tilemap?

    In the first case, you probably should start from the elemental question, which is how to modify a Tilemap runtime. That will most likely return quite a few search engine hits.
     
  3. aybarsmete1

    aybarsmete1

    Joined:
    Oct 26, 2019
    Posts:
    43
    I'm looking for a system that allows you to build on Tilemap while in game, like Terraria.
     
  4. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    Try Youtube/google, they will bring a few hits.
     
  5. JasonBricco

    JasonBricco

    Joined:
    Jul 15, 2013
    Posts:
    956
    I haven't found Unity's tilemap system to be very good for this and so I wrote my own system. I found Unity's system to be more tailored to building in the Unity editor. A few issues I had:

    - Performance wasn't good when setting large amounts of tiles at once, especially when using tilemap colliders.
    - Functions for setting groups of tiles at once were buggy and behaved incorrectly (hopefully fixed by now).
    - Performance for a large tile map is questionable. Unity has a culling system for rendering, but only for rendering.
    - Trying to use a separate tilemap for 'chunks' has way more performance overhead than writing your own system using Unity sprites (or meshes), and I found behaved incorrectly - tilemaps weren't visible despite tiles being on screen, tiles appearing at incorrect locations, etc.

    Some of this was caused by the tilemap system having almost no useful documentation about the internal workings of the system and not understanding it as a result.

    I believe if you don't plan to make a large tilemap and don't plan to set large amounts of tiles at once, the built in system should be sufficient. Depends on your needs.

    Edit: for clarity, it IS "possible" - you can create/set tiles at runtime just fine. It's really just a matter of performance.
     
    MisterSkitz likes this.
  6. RUNETHERABB1T

    RUNETHERABB1T

    Joined:
    Apr 6, 2019
    Posts:
    1
    Anywere i can get source code for that or a guide on how to make something simillar?
     
  7. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,726
    Source code for something as complex and intimately tied to its ultimate use case isn't really gonna be helpful.

    The Unity API for setting tiles within a Tilemap is essentially one function: SetTile()

    That's it.

    If you want examples of 2D tile editors the internet is full of them in various flavors.

    The basic concepts of an editor will be found in the collective wisdom of many tutorials, both for Unity and other engines, or even just abstractly talked about without engine dependence.

    Screen Shot 2022-09-21 at 11.10.36 AM.png

    When you work through tutorials for this purpose, make double triple sure you do Step #2 below!!

    Tutorials and example code are great, but keep this in mind to maximize your success and minimize your frustration:

    How to do tutorials properly, two (2) simple steps to success:

    Step 1. Follow the tutorial and do every single step of the tutorial 100% precisely the way it is shown. Even the slightest deviation (even a single character!) generally ends in disaster. That's how software engineering works. Every step must be taken, every single letter must be spelled, capitalized, punctuated and spaced (or not spaced) properly, literally NOTHING can be omitted or skipped.

    Fortunately this is the easiest part to get right: Be a robot. Don't make any mistakes.
    BE PERFECT IN EVERYTHING YOU DO HERE!!

    If you get any errors, learn how to read the error code and fix your error. Google is your friend here. Do NOT continue until you fix your error. Your error will probably be somewhere near the parenthesis numbers (line and character position) in the file. It is almost CERTAINLY your typo causing the error, so look again and fix it.

    Step 2. Go back and work through every part of the tutorial again, and this time explain it to your doggie. See how I am doing that in my avatar picture? If you have no dog, explain it to your house plant. If you are unable to explain any part of it, STOP. DO NOT PROCEED. Now go learn how that part works. Read the documentation on the functions involved. Go back to the tutorial and try to figure out WHY they did that. This is the part that takes a LOT of time when you are new. It might take days or weeks to work through a single 5-minute tutorial. Stick with it. You will learn.

    Step 2 is the part everybody seems to miss. Without Step 2 you are simply a code-typing monkey and outside of the specific tutorial you did, you will be completely lost. If you want to learn, you MUST do Step 2.

    Of course, all this presupposes no errors in the tutorial. For certain tutorial makers (like Unity, Brackeys, Imphenzia, Sebastian Lague) this is usually the case. For some other less-well-known content creators, this is less true. Read the comments on the video: did anyone have issues like you did? If there's an error, you will NEVER be the first guy to find it.

    Beyond that, Step 3, 4, 5 and 6 become easy because you already understand!