I have the head and neck of a skeletal mesh set up to use a different material element than the body and I’m using a dynamic material instance which has an opacity mask of 0.5 and a corresponding parameter whose value I can switch between 0 (when I want the head invisible as the pawn is possessed by the player) and 1 (when the pawn isn’t possessed by the player and I therefore want the head to be seen).
This all works fine, but the problem I’m having is that the shadow disappears when the head is masked out whereas I’d like the shadow to always be visible. I’ve tried setting “Cast Hidden Shadow” to true in the skeletal mesh’s details on the pawn’s components tab but that only seems to preserve the shadow of hidden meshes with visible materials whereas I need a shadow from a non-hidden part of a mesh which is temporarily masked out.
Is there any way to specify in the material I’m using that the opacity mask should be ignored when generating the shadow? (I’m trying to avoid making the head a separate mesh, partly because I’m concerned that making the head detachable will leave a visible seam where it joins the torso but also because I don’t want to complicate any IK and animation stuff I’ll be doing later).
Alternatively is there a way to dynamically set “Owner No See” or “Hidden” to true for only a part of a mesh (in my case, the part which has a certain material element)?
Hey DickDastardly -
To directly answer your question no there is not a way to have something masked and still cast a shadow as if it were unmasked. However, I have a work around which will not greatly effect your skeletal mesh. Go into your modelling program and select the head polygons and give them a different material in Maya or setup a Multi-SubObject material in Max. Then you can trigger the Cast Shadows call on the different Skeletal Mesh Material Elements to turn on and off the shadows for your head.
Thanks very much for getting back to me. With regard to your suggested workaround I already have the head polygons set up to use a different zone of a multi sub object material in Max so they’re already using a different material element than the body polygons once imported into UE4.
My problem is that I don’t know how to “trigger the Cast Shadows call on the different Skeletal Mesh Material Elements”. I’m working in blueprints rather than C++ and I’ve found a BP function called “Set Cast Shadow” but I’m not sure what to wire its target to so that it affects just material element 0 on my skeletal mesh (and not the other elements).
My other concern is that, given that you’ve said fully masked materials can’t cast shadows, I need a new method to toggle the visibility of the head rather than my current technique of using a dynamic material instance with an opacity mask parameter. So what would I wire the target of “Set Owner No See” or “Set Hidden in Game” to in order that they only affect a single material element rather than the whole mesh?
Hey DirkDastardly -
Ah I understand a little better now. I did some hunting around and currently there is no way to achieve that exact control. You will probably have to setup a two mesh system in blueprint currently one with the head and one without. This is actually how we are doing the setup in our first and third blueprint switch.
As a side note though I have put in a request to expose the Element Cast Shadow to blueprints for control, but it will probably be a bit before the developers can get around to it.
I’m guessing you’re setting up a “True First Person” character and need the head mesh hidden so the camera doesn’t clip through it?
Another way to approach this is to separate the head from the mesh entirely. If you rig your mesh like normal and then save one version as MeshName_NoHead and delete only the head polys then save another copy as MeshName_Head and delete everything but the head polys. Then inside your blueprint you would add two skeletal meshes, the body and the head (this will unfortunately double the amount of bones but as long as it’s not multiplayer it won’t impact performance too badly). Then on the head mesh, you can actually tell it to cast hidden shadows in the details and when the head is hidden you’ll still see a shadow.
If twice the number of bones doesn’t work for you, skin the head to a single bone and then parent that mesh to the head bone of your character’s skeleton. Then there’s only one extra bone. With some tweaking you should be able to get it into place and then it’ll synch up with the rest of the mesh.