{"id":692,"date":"2020-10-26T10:36:12","date_gmt":"2020-10-26T10:36:12","guid":{"rendered":"https:\/\/half4.xyz\/?p=692"},"modified":"2024-01-25T10:03:29","modified_gmt":"2024-01-25T10:03:29","slug":"character-clothing-part-4-ue4-logic","status":"publish","type":"post","link":"https:\/\/half4.xyz\/index.php\/2020\/10\/26\/character-clothing-part-4-ue4-logic\/","title":{"rendered":"Character Clothing \u2013 Part 4: UE4 Logic"},"content":{"rendered":"<h2 class=\"wp-block-heading\">Table of Contents<\/h2>\n<blockquote class=\"wp-embedded-content\" data-secret=\"keke5qgXb5\"><p><a href=\"https:\/\/half4.xyz\/index.php\/2020\/10\/22\/character-clothing-zone-culling\/\">Character Clothing Zone Culling<\/a><\/p><\/blockquote>\n<p><iframe class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;Character Clothing Zone Culling&#8221; &#8212; half4.xyz\" src=\"https:\/\/half4.xyz\/index.php\/2020\/10\/22\/character-clothing-zone-culling\/embed\/#?secret=5vhNMsUN2E#?secret=keke5qgXb5\" data-secret=\"keke5qgXb5\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n<blockquote class=\"wp-embedded-content\" data-secret=\"8KrgHVqbgH\"><p><a href=\"https:\/\/half4.xyz\/index.php\/2020\/10\/22\/character-clothing-part-2-maya\/\">Character Clothing &#8211; Part 2: Maya<\/a><\/p><\/blockquote>\n<p><iframe class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;Character Clothing &#8211; Part 2: Maya&#8221; &#8212; half4.xyz\" src=\"https:\/\/half4.xyz\/index.php\/2020\/10\/22\/character-clothing-part-2-maya\/embed\/#?secret=sKMiJyTcst#?secret=8KrgHVqbgH\" data-secret=\"8KrgHVqbgH\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n<blockquote class=\"wp-embedded-content\" data-secret=\"EsxEqDVyog\"><p><a href=\"https:\/\/half4.xyz\/index.php\/2020\/10\/22\/character-clothing-part-3-ue4-shaders\/\">Character Clothing &#8211; Part 3: UE4 Shaders<\/a><\/p><\/blockquote>\n<p><iframe class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;Character Clothing &#8211; Part 3: UE4 Shaders&#8221; &#8212; half4.xyz\" src=\"https:\/\/half4.xyz\/index.php\/2020\/10\/22\/character-clothing-part-3-ue4-shaders\/embed\/#?secret=HcPqiJcZYY#?secret=EsxEqDVyog\" data-secret=\"EsxEqDVyog\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n<blockquote class=\"wp-embedded-content\" data-secret=\"qrfBo6zR6f\"><p><a href=\"https:\/\/half4.xyz\/index.php\/2020\/10\/26\/character-clothing-part-4-ue4-logic\/\">Character Clothing \u2013 Part 4: UE4 Logic<\/a><\/p><\/blockquote>\n<p><iframe class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;Character Clothing \u2013 Part 4: UE4 Logic&#8221; &#8212; half4.xyz\" src=\"https:\/\/half4.xyz\/index.php\/2020\/10\/26\/character-clothing-part-4-ue4-logic\/embed\/#?secret=qYoVWxQWLU#?secret=qrfBo6zR6f\" data-secret=\"qrfBo6zR6f\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n<h2 class=\"wp-block-heading\">Blueprints<\/h2>\n<p>First, create a new Actor Component Blueprint<\/p>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"wp-image-658\" src=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-42.png\" sizes=\"(max-width: 693px) 100vw, 693px\" srcset=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-42.png 693w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-42-300x242.png 300w\" alt=\"\" width=\"693\" height=\"560\" \/><\/p>\n<p>Call it \u201cBP_MeshZoneCulling\u201d and open it up\u2026<\/p>\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" class=\"wp-image-660\" src=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-44.png\" alt=\"\" width=\"200\" height=\"252\" \/><\/figure>\n<p>Next to it, create a Enumeration, call that \u201cENUM_Cullzones\u201d<\/p>\n<p><img decoding=\"async\" class=\"wp-image-662\" src=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-45-1024x255.png\" sizes=\"(max-width: 1024px) 100vw, 1024px\" srcset=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-45-1024x255.png 1024w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-45-300x75.png 300w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-45-768x191.png 768w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-45.png 1342w\" alt=\"\" width=\"1024\" height=\"255\" \/><\/p>\n<p>Open up the Enumerator and add in 24 rows (for UE4, in Unity you\u2019ll have to do this in C# and have up to 32), and check the Bitmask flags option. Name each of the Display Name fields appropriately, like so:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-664\" src=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-47-1024x845.png\" sizes=\"(max-width: 1024px) 100vw, 1024px\" srcset=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-47-1024x845.png 1024w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-47-300x248.png 300w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-47-768x634.png 768w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-47.png 1513w\" alt=\"\" width=\"1024\" height=\"845\" \/><\/p>\n<p>The important thing here is the order \u2013 it must match the order of your zones in your UV set. Save it and open our Blueprint.<\/p>\n<p>In the Blueprint, create a new integer variable and set it to be a Bitmask and the Enum to be your new Enumeration in the Details Panel. Make it public by checking the \u201ceye\u201d icon. Duplicate this for every layer of clothing you have, and the Body:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-684\" src=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-65-1024x516.png\" sizes=\"(max-width: 1024px) 100vw, 1024px\" srcset=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-65-1024x516.png 1024w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-65-300x151.png 300w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-65-768x387.png 768w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-65-1536x775.png 1536w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-65-2048x1033.png 2048w\" alt=\"\" width=\"1024\" height=\"516\" \/><\/p>\n<p>Next, Create a new Actor Blueprint for your character. Add in a new Skeletal Mesh Component for each layer of clothing, and one for your base character. Also add in our new Actor Component.<\/p>\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-673\" src=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-56-1024x717.png\" sizes=\"(max-width: 1024px) 100vw, 1024px\" srcset=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-56-1024x717.png 1024w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-56-300x210.png 300w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-56-768x537.png 768w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-56-1536x1075.png 1536w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-56.png 1795w\" alt=\"\" width=\"1024\" height=\"717\" \/><\/figure>\n<p>Go back into the Actor Component and add in a new variable for the body &amp; clothing skeletal meshes, like so:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-674\" src=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-57-1024x655.png\" sizes=\"(max-width: 1024px) 100vw, 1024px\" srcset=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-57-1024x655.png 1024w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-57-300x192.png 300w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-57-768x491.png 768w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-57-1536x983.png 1536w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-57.png 1926w\" alt=\"\" width=\"1024\" height=\"655\" \/><\/p>\n<p>Whilst you\u2019re here, add in 4 Dynamic Material Instance arrays to the variable list. To be able to edit our Materials from the BP we need to use Dynamic Material Instances:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-685\" src=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-66-1024x356.png\" sizes=\"(max-width: 1024px) 100vw, 1024px\" srcset=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-66-1024x356.png 1024w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-66-300x104.png 300w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-66-768x267.png 768w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-66-1536x534.png 1536w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-66-2048x712.png 2048w\" alt=\"\" width=\"1024\" height=\"356\" \/><\/p>\n<p>Back into the Character Actor now, head into the event graph and add in the following logic \u2013 it assigns your skeletal mesh components into the corresponding variables in the Actor Component:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-675\" src=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-58-1024x705.png\" sizes=\"(max-width: 1024px) 100vw, 1024px\" srcset=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-58-1024x705.png 1024w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-58-300x206.png 300w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-58-768x529.png 768w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-58-1536x1057.png 1536w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-58.png 1816w\" alt=\"\" width=\"1024\" height=\"705\" \/><\/p>\n<p>Return into the Actor Component and hook up the following logic on a custom event \u201cSetup Materials\u201d:<\/p>\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-681\" src=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-62-1024x568.png\" sizes=\"(max-width: 1024px) 100vw, 1024px\" srcset=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-62-1024x568.png 1024w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-62-300x166.png 300w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-62-768x426.png 768w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-62-1536x852.png 1536w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-62-2048x1137.png 2048w\" alt=\"\" width=\"1024\" height=\"568\" \/><\/figure>\n<p>&nbsp;<\/p>\n<p>Quickly, back into the Player Character Blueprint and hook up your event to run after the Being Play has finished, like so:<\/p>\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-683\" src=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-64-1024x172.png\" sizes=\"(max-width: 1024px) 100vw, 1024px\" srcset=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-64-1024x172.png 1024w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-64-300x51.png 300w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-64-768x129.png 768w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-64-1536x259.png 1536w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-64.png 1966w\" alt=\"\" width=\"1024\" height=\"172\" \/><\/figure>\n<p>Finally now \u2013 back into the Actor Component. Under Event tick, hook up your Dynamic Material Instances to update every frame:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-686\" src=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-67-1024x533.png\" sizes=\"(max-width: 1024px) 100vw, 1024px\" srcset=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-67-1024x533.png 1024w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-67-300x156.png 300w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-67-768x400.png 768w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-67-1536x799.png 1536w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/image-67-2048x1065.png 2048w\" alt=\"\" width=\"1024\" height=\"533\" \/><\/p>\n<p>Obviously, you\u2019ll want to run the Event off something other than Tick, but this is just to get you going.<\/p>\n<p>This takes the bitmask values you\u2019ve defined and pushes those through to the Materials.<\/p>\n<p>You can now put your Actor BP into the level, hit Play and start testing.<\/p>\n<figure class=\"wp-block-video\"><video src=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/10\/UV_Cull_Demo.mp4\" controls=\"controls\" width=\"300\" height=\"150\"><\/video><\/figure>\n<p>This should be enough to get you going. You can create Databases in Unreal Engine 4 to store all the culling zones data, and you can expand the logic of the system to sensibly know which areas to hide on the skin and which to not.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Table of Contents Character Clothing Zone Culling Character Clothing &#8211; Part 2: Maya Character Clothing &#8211; Part 3: UE4 Shaders Character Clothing \u2013 Part 4: UE4 Logic Blueprints First, create a new Actor Component Blueprint Call it \u201cBP_MeshZoneCulling\u201d and open it up\u2026 Next to it, create a Enumeration, call that \u201cENUM_Cullzones\u201d Open up the Enumerator and add in 24 rows (for UE4, in Unity you\u2019ll have to do this in C# and have up to 32), and check the Bitmask flags option. Name each of the Display Name fields appropriately, like so: The important thing here is the order \u2013 it must match the order of your zones in your UV set. Save it and open our Blueprint. In the Blueprint, create a new integer variable and set it to be a Bitmask and the Enum to be your new Enumeration in the Details Panel. Make it public by checking the \u201ceye\u201d icon. Duplicate this for every layer of clothing you have, and the Body: Next, Create a new Actor Blueprint for your character. Add in a new Skeletal Mesh Component for each layer of clothing, and one for your base character. Also add in our new Actor Component. Go back into the Actor Component and add in a new variable for the body &amp; clothing skeletal meshes, like so: Whilst you\u2019re here, add in 4 Dynamic Material Instance arrays to the variable list. To be able to edit our Materials from the BP we need to use Dynamic Material Instances: Back into the Character Actor now, head into the event graph and add in the following logic \u2013 it assigns your skeletal mesh components into the corresponding variables in the Actor Component: Return into the Actor Component and hook up the following logic on a custom event \u201cSetup Materials\u201d: &nbsp; Quickly, back into the Player Character Blueprint and hook up your event to run after the Being Play has finished, like so: Finally now \u2013 back into the Actor Component. Under Event tick, hook up your Dynamic Material Instances to update every frame: Obviously, you\u2019ll want to run the Event off something other than Tick, but this is just to get you going. This takes the bitmask values you\u2019ve defined and pushes those through to the Materials. You can now put your Actor BP into the level, hit Play and start testing. This should be enough to get you going. You can create Databases in Unreal Engine 4 to store all the culling zones data, and you can expand the logic of the system to sensibly know which areas to hide on the skin and which to not.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-692","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/half4.xyz\/index.php\/wp-json\/wp\/v2\/posts\/692"}],"collection":[{"href":"https:\/\/half4.xyz\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/half4.xyz\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/half4.xyz\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/half4.xyz\/index.php\/wp-json\/wp\/v2\/comments?post=692"}],"version-history":[{"count":4,"href":"https:\/\/half4.xyz\/index.php\/wp-json\/wp\/v2\/posts\/692\/revisions"}],"predecessor-version":[{"id":1273,"href":"https:\/\/half4.xyz\/index.php\/wp-json\/wp\/v2\/posts\/692\/revisions\/1273"}],"wp:attachment":[{"href":"https:\/\/half4.xyz\/index.php\/wp-json\/wp\/v2\/media?parent=692"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/half4.xyz\/index.php\/wp-json\/wp\/v2\/categories?post=692"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/half4.xyz\/index.php\/wp-json\/wp\/v2\/tags?post=692"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}