Drinking from glasses BP function, plus a link to my anime style shader

Here’s a BP function and a Content demo to use mesh slicing (UE 4.13 or later) to allow characters to “drink” from glasses.

Here’s a short movie clip:

For each type of container, you need at least three meshes – the container volume (including the “top”, so a cylindrical glass needs both a bottom and top surface), the container opening (which can be the same as the top surface), and whatever mesh you use for the glass itself.

You should make Child blueprints of the prototype for various shapes of glasses.

Important note: you need to enable “Allow CPUAccess” in the mesh settings for the container volume and the container opening for mesh slicing to work (and if you want sloshing, you need to add two sockets to the container volume mesh for PourTop and PourBottom – PourTop should be the center of the container opening mesh, while PourBottom should be BELOW the bottom of the container, about .25 farther than the total top-bottom height).

To try out the demo, create a new empty project and put the files into the Content folder. Open the project and open the TestLevel level.

The UE4 forum uploader seems to choke on the demo .zip file, so I put it up on archive.org:
https://archive.org/download/Drinkin…ingContent.zip

Here is just the Drinking BP function:
item_glass_prototype.uasset.zip

When playing the demo, here are keys that do things:
On the keypad, 8,6,4, and 2 tilt the glasses 5° away, right, left, and towards the initial camera position. Holding down shift tilts 20° at a time (enough to slosh), and alt tilts 1°.
‘F’ refills all the glasses up to 95%
‘H’ toggles sloshing (default off)
‘J’ “jolts” the drinks to have them slosh a little, if sloshing is enabled, and they will slosh in whatever direction they were last tilted. Shift-J will be a big jolt with a fixed direction to show how that can be done.
‘L’ toggles animated drinking (default off)
‘V’ toggles between water-like viscosity and thick oil
WASD + mouse let you move around as normal first person.

The function returns a StillMoving boolean – examine the demo to see how it enables and disables Tick Events. You can leave them on all the time, but that consumes CPU time; it’s better if you can enable it only when you know it’s needed, and disable it again when StillMoving returns false.

The FullFraction is a fraction of the height of the container volume mesh – it isn’t a fraction of the volume. The martini glass at .5 has much less than half the total volume.

The inputs:
DrinkingFunction.png

Target can just be Self.

Delta Seconds should be from the tick event

Liquid Material is whatever material you have for the liquid in the container.

Liquid Material Surface is the surface material. This can be the same as Liquid Material, but for translucent materials, the surface should be slightly darker or it blends in with the volume and there’s no ‘edge’ on the side of the glass. The martini and brandy glasses are like this.

Drain Speed is how much to reduce the FullFraction each tick until the liquid level is at or below the Min Lip Height.

Drain All Degrees is the angle where all the liquid will drain out, with 180 being upright, counting down – for cylinders, they drain at 90 degrees. Martini is about 120 degrees, and the brandy glass about 70 degrees.

Min Lip Height is how far above the edge of the glass the liquid will stop – 0 will have it stop at the edge.

Max Lip Height is how far above the edge of the glass the liquid will start at – 0 will have it start at the edge. If Max Lip Height is greater than Min Lip Height, the liquid will “drain” by Drain Speed until it goes down to Min Lip Height.

Slosh Decay Time Seconds is how long before sloshing decays to no movement.

Slosh Magnitude is how violently it sloshes – 0 disables sloshing.

Slosh Pseudo Viscosity is how thick the liquid is when sloshed – 1 is water, higher numbers are “thicker”

Min Slosh Fraction is where sloshing gets dampened further to prevent sloshing from going “under” the bottom of the glass.

Max Slosh Fraction is where sloshing gets dampened further to prevent sloshing from going “over” the top of the glass.

Slosh Angle Scale is just a slosh adjuster – 1 is normal, smaller values reduce the sloshing, larger increases it.

Shrink Liquid reduces the size of the liquid mesh so it doesn’t exactly overlap the container itself. This allows you to use the same mesh for the container volume and the container, without have two materials “fight” over which one is drawn. A value of .99 shrinks it just a bit so it fits “inside” the container.

Low Level Adjust is a fake “minimum” liquid level for odder shapes like the martini and brandy glasses; otherwise, a nearly-empty upright glass appears to partly refill itself magically when tilted, due to all the klugery going on.

The three milk glasses are all the same object with different Z scales. While you can scale Z differently from X and Y, it makes the sloshing look weird.
[HR][/HR]

My anime shader is here in this thread.

And here is a tiny BP to have your pawn hear sounds instead of the follow camera hearing them in 3rd person games.

The original zip file is here:
https://archive.org/details/drinkingcontent

One that’s a full working project and tested after imported into 4.23.1 is here:

2 Likes

Pretty impressive. Really good work. Now we have to make a drinking game. :slight_smile: Thanks for sharing!

Wow, that looks awesome. I always love seeing liquids moving in games. Great job.

Please note that converting from 4.15 to 4.15.1 can remove the exec input of IsValid branches, and there is such a branch in the DrinkingMeshSetup macro, so you might need to re-hook it up.

When launching with 4.15.0 all glasses are empty for me. I can tilt them, but F does nothing.
Any ideas what might be wrong?

Check the IsValid input in the DrinkingMeshSetup macro, it should have an exec connected from the input, but another user had the same problem. Also make sure “Allow CPUAccess” is on in the meshes.

Also you might get Pending Kill warnings – I should have set drink_Liquid to null right after I destroy it in the same DrinkingMeshSetup macro.

Super cool! Old post, but I’m not sure how else to contact you. Can I credit you in a project that I’d like to use this in?