x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How to Add C++ Class Functionality or Blueprints to Tiles within a TileSet and/or TileMap?

What I am trying to do: I have been trying to create a top down tile based game using Unreal’s Paper2D functionality. I was wondering if it was possibly to add class functionality to tile within the TileSet and/or the TileMap.

Problem: My overarching problem is that I am unable to add objects to the tile map that have functionality beyond collision. I would like to refrain from just placing something on top of my TileMap within the level. I feel that the TileMap would be more coherent if all the objects could be placed within the TileMap editor.

Example: For example, how would I go about creating a tile like a pressure plate that would trigger when it was stepped on by the player. If I create a class/blueprint that has all the functionality of my pressure plate how can I apply it to my Tile within the TileSet to make sure that the tile’s behavior is consistent when placed within the TileMap.

Additional Info: I did see in the TileSet editor that there is an option to add meta data to a tile, but the only metadata that can be added is a single string. Furthermore, the TileSet editor recommends that I use the Tile’s metadata as an index within a DataTable. Is this metadata something that I could use to attach a class to a given Tile by referencing the DataTable.

Thank you very much for your time and consideration in reading this post. I look forward to hearing back from you. Thanks again for the help.

Product Version: UE 4.12
Tags:
more ▼

asked Jun 15 '16 at 07:34 AM in C++ Programming

avatar image

Jackkell
96 3 5 11

avatar image falola Dec 19 '16 at 12:54 AM

I'm wondering the same as well, did you ever solve this?

avatar image Jackkell Jan 15 '18 at 05:58 AM

I never did solve this because I made this post awhile ago and I was still new to Unreal and Paper2D thought it was never going to get answered but Chaosian gave a beautifully crafted answer below here.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

Alright, I figured it out with Blueprint (you can probably do it in C++ though). Even though you'll probably never see this, hopefully someone will come across it - as there's basically no documentation on these features.

Tileset editor.

Alright, so step 1 is to get your tileset from a texture. For my example, I'll be using some classic Zelda sprites courtesy of 'Darth RPG'. The tileset size I'm using is 16x16, which will be important down the line.

User Data Name field

Step 2 is to set up both collision AND metadata on the tile in question you want to perform the blueprint functionality. I'll be using a staircase. To set up the metadata, input text into the "Used Data Name" field. For my example, I'm using the string "Stairs". Also note from the image, my collision doesn't encompass the entire tile. It's more like 9x9 for 16x16 tile.

Placing tileset on a tilemap

Place your tilesets on your tile map, and then place that in the world. This is my example scene, that allows me to test the collision of the pillars, and my staircase in the middle.

alt text

NOW comes the big important step, the blueprint. Long story short, when we hit collision, we want to get the metadata of the tile we're colliding with. Unfortunately there is no "get tile" for this sort of thing, so we have to make one. I'm doing this in my character, but you would probably be better off doing this in a component or fired off via a function. In this code, I start off Event Hit (an occurance for any collision event) and take the Hit result. Breaking the hit result I get the hit actor, and cast to PaperTileMapActor. Getting the casted actor's location, the location of our tilemap, I subtract the Impact Point from the Hit Result to get the aproximate position of our tileset. That point needs to be converted to a tile that can be found, and Metadata extracted from. Breaking the vector from that subtraction node, I get the X and Y values and divide them by my tile size (16). These values might get sketchy if you aren't working on a 1,1,1 scale like I am, and you'll probably need to multiply them by a scale if you aren't - but regardless, you'll want to round the divided results. In my example I invert my Y value but that might not be nescessary depending on your setup. The imporant step, is for you to finally get the render component from the PaperTileMapActor you casted to earlier, and "Get Tile" from it. Input the rounded X and Y values into the appropriate slots. From there you perform the final and most important step: "Get Tile User Data", which will hopefully return the Text of the tile's Metadata.

alt text The end result, from by debug outputs, is the Metadata text for the tile. From there, it's easy enough. Perform a switch case statement on the metadata names to perform whatever function you want. The nice thing about this solution is that if I ever want any staircase in any tileset to perform the same function, I'd just have to give it the metadata of "Stairs".

tileset6.png (479.8 kB)
tileset1.png (148.0 kB)
tileset3.png (56.8 kB)
tileset4.png (69.7 kB)
tileset5.png (164.2 kB)
more ▼

answered Apr 10 '17 at 06:47 AM

avatar image

Chaosian
111 4 12 12

avatar image aleksvander Aug 29 '17 at 12:43 PM

Thank you. Not elegant, but I think it's quite workable. Came similar ideas in the head.

I wanted use custom cells with many sprites, i mean just sprites with flipbook without tiles, used constuctor script for support our custom cells. So, But i thing it's a large overload of the scene, m.b. tilemaps will be best solution.

plus

you can use this methods for calculable position alt text

0123.png (348.5 kB)
avatar image Jackkell Jan 15 '18 at 06:06 AM

I thought this problem was never going to get answered. Over the past couple months or so I have really gotten back into Unreal development so I just now saw your answer Chaosian. I wanted to thank you for giving such a well thought out and beautifully crafted answer. Thank you very much for your time it is very much appreciated. When I go back to making projects using Paper2D I will definitely be referencing this.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Someone thought about the logic of determining the surface to play a certain sound of walking depending on the surface? I understand... we can use key or composite_key that do it, but m.b. exist more elegant way. Or use invisible collision. If i can get layer name, that can be key.

more ▼

answered Jan 15 '18 at 06:44 AM

avatar image

aleksvander
11 2 2

avatar image mgondim Mar 08 '18 at 03:51 PM

Hello all, I m trying to edit tiles in runtime.. is possible? Like destroy one simple tile? I manage to do that with GroupPaperSprite but its not the best way I think... I trying to remove a simple tile with this...

Thank you very much for your time and consideration in help me too. I look forward to hearing back from you. Thanks again for the help.

[1]: /storage/temp/233126-sem-titulo-1.png

sem-titulo-1.png (407.2 kB)
(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question