Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Destructibility and interactive tiles

Discussion in '2D Experimental Preview' started by Iain-Lobb, Jun 3, 2016.

  1. Iain-Lobb

    Iain-Lobb

    Joined:
    Jan 11, 2013
    Posts:
    30
    What is the proposed solution for allowing:
    1) Destructibility - can the tilemap be changed at runtime, like in Spelunky / Bomberman / Terraria?
    and
    2) interactive tiles? Would you just line up game objects to the grid? Maybe there could be some tooling to help with this?
     
  2. der_r

    der_r

    Joined:
    Mar 30, 2014
    Posts:
    259
    The tilemap can already be edited at runtime.

    For interactive tiles, you have several options:

    1) Create your own scripted tiles as per documentation.

    2) Add a prefab to a basic tile... the prefabs get instantiated when you run the game.

    3) Manually check and manipulate tiles via script. The Tilemap has a Grid component that you can use to transform world coordinates to grid coordinates, which you can then use to query tiles on a layer and do different things based on that.

    Hope that helps!
     
  3. Iain-Lobb

    Iain-Lobb

    Joined:
    Jan 11, 2013
    Posts:
    30
    That all sounds great! thanks, will try to test it all out
     
  4. keely

    keely

    Joined:
    Sep 9, 2010
    Posts:
    967
    Like said, the system is pretty open-ended, so several options are available on how to do interactive tiles. We will document best practices eventually, but it is too early for that now.

    I'd say that one of the core reasons that tilemap exists in the first place, is that you don't need to have every tile to be a gameobject. This means not only performance gains, but also makes editing levels more clean and convenient.

    The more your tile is interactive and complex, the more you want to use an actual gameobject. That is most convenient way in Unity to describe complex things. (Note that the tile itself can provide this gameobject)

    On the other hand, the more you have instances of certain tile, the less you want them to be actual gameobjects, due to performance reasons. For example having 100x100 level with all tiles being destructible, you are looking at 10k gameobjects. Unity can do that (depending on components), but at some point it starts to break down.

    So for destructible terrain, I would use single component (script) that handles the entire destructible terrain logic for entire level. The actual terrain tiles are just dummies.

    On the other hand, lets say an animated door with sound and scripts, I would just use tile that instantiates prefab or simply overlay GO with spriterenderer on top.
     
    birdyyakker and Rallix like this.
  5. Iain-Lobb

    Iain-Lobb

    Joined:
    Jan 11, 2013
    Posts:
    30
    thanks - this is awesome - do you think a Terraria-scale grid will be feasible with this system?
     
  6. keely

    keely

    Joined:
    Sep 9, 2010
    Posts:
    967
    We haven't really focused on performance yet (premature optimization is evil right!), so I'm shooting blind here. My conservative guess is that you probably can't pull off smooth Terraria (8400 x 2400, 20M tiles) with the basic single tilemap setup. You might need to build your own systems that stream multiple instances of small tilemaps side-by-side near the camera or something like that.

    If you test bigger procedural maps yourself, I'd be very interested to know where we stand in the perf right now.
     
  7. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
    Tested one script which paints 4096x4096 random tiles,
    took almost 2 minutes to generate (using 2 for loops with random.range) and 5.5gb memory..

    Still pans smoothly at close zoom in scene view, but crashes if start to zoom out too much..
     
    Xepherys and keely like this.
  8. Xepherys

    Xepherys

    Joined:
    Sep 9, 2012
    Posts:
    204
    Would you be willing to share your script?
     
  9. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
    yup, its here random tiles
     
  10. OccularMalice

    OccularMalice

    Joined:
    Sep 8, 2014
    Posts:
    169
    mgear likes this.
  11. tabrooksy

    tabrooksy

    Joined:
    Jan 21, 2018
    Posts:
    6