Download

Book reading mechanic for changing materials when the page turn animation starts

Okay, so I’ve got a book mesh in my game that I’ve already successfully animated so that when the player presses the “F” or “B” key, a page will flip forwards or backwards. Obviously, I didn’t model every individual page of the book, as I’m just looking to create the illusion of new pages being turned. I’ve already got the texture for the book and all of its pages, but I’m not exactly sure as to how to make it so the material of the book changes every time the user presses the corresponding key to flip the page forward or backward. I’m thinking something with arrays, but since I’m relatively new to this, I don’t exactly know how to implement it, and it’d be awesome if someone could point me in the right direction.

You could use a Data Table for holding each of your pages. This will help you get a reference the associated materials when you need to, and would be more user friendly when it comes to adding all the pages to a list of some sort.

Data tables use Rows, so when the user presses one of the buttons (back a page, or forward a page) you can Get the associated row via GetDataTableRowNames > Get Array Element IntCurrentPage+1 > Get Data Table Row for returned Array Element. You can then break open the struct for that page to access the material and then use that material reference to Set that of your page mesh.

Hope this helps!

After looking into the Data Table functionality, it looks like it requires knowledge of C++ coding. Do you think there might be any other way to go about this only using blueprints?

A rudimentary explanation of what I’m trying to figure out would go something like this:

User presses F key, next material is applied to the mesh, user presses F key again, and the next material is applied to the mesh. If they press the B key, then the previous material is applied to the mesh. So on and so forth.

You can do it through C++, but it is also easily done in Blueprints :slight_smile:

You should create two files. One Structure (Content Browser > Blueprints > Structure) and a Data Table (Content Browser > Miscellaneous > Data Table) and link your Struct to your data table when requested.

bc3248d362a0fedb7ffaa213c2925d3f08ea742a.png

The structure should have the variable types you wish to access, so in this case it would be a “Material”. In the data table you will then be able to create rows for each page and assign a material to each.

As for the BP side of things, I was able to quickly put together a basic example of what I mentioned above.

ac94cc063a3a8918fc45f73be8c503bb3c05333d.png

Also just a quick note, keep in mind that because the returned “Row Names” array is an Array, it will start at page 0 then moves to 1, 2 , etc. As long as your IntCurrentPage Starts at 0 it should start from page 1 of the data table (Your book)

Hope this clears things up a bit more!