ruyo / VRM4U

Runtime VRM loader for UnrealEngine4
Other
1.3k stars 170 forks source link

Outline/MToonAttachActor issues #349

Closed andreiagmu closed 5 months ago

andreiagmu commented 5 months ago

Describe the bug I'm having some difficulty understanding how to properly add/adjust/reuse the outlines of my game's characters. Please watch the attached video to better understand my issues.

My main questions are:

Video https://www.youtube.com/watch?v=R0ui250cwZ8

[Chapters] 0:00 - I added MToonAttachActor to SkeletalMeshActor. 0:32 - I tried duplicating the SkeletalMeshActor in level, MToonActor wasn't duplicated along with it. 1:11 - I manually added MToonAttachActor to the duplicate SkeletalMeshActor.

1:40 - Adjusting global outline parameters. 2:02 - Searching for per-model outline parameters (I haven't found those parameters). 2:52 - Taking a look at MaterialInstanceDynamic's parameters (I'm guessing I shouldn't mess with these directly, right?).

4:00 - Testing a character controller Blueprint, which dynamically spawns the character, using the same Skeletal Mesh Asset (my VRM character). The spawned character doesn't have the MToonAttachActor/outlines/custom shadow map. 4:30 - Opening the character controller Blueprint. It's based on UE5's Third-Person Template. 5:05 - Inside the character controller Blueprint, I tried attaching MToonAttachActor to the Mesh component. This didn't work. 5:50 - I played the level. Again, the spawned character doesn't have the MToonAttachActor/outlines/custom shadow map. 6:00 - Notice the empty MToonAttachActor on the spawned character.

Unreal Engine Version: UE 5.3.2

Additional context I'm using VRM4U_5_3_20231126 (latest release)

andreiagmu commented 5 months ago

Regarding question 1: I just noticed that if I explicitly select the parent actor and its child actors in the Outliner view, then duplicating the parent and its children works as expected. Using the Select Immediate Children shortcut (Ctrl + Alt + D) also helps with this.

This seems to be a general Unreal Engine thing. I came from Unity game development, so I expected the child actors to be automatically duplicated along with the parent actor. šŸ¤£

I'm still trying to figure out how to adjust the outline parameters per-model instead of globally, and the proper way to use MToonAttachActor with a dynamically spawned character.

andreiagmu commented 5 months ago

Regarding question 2: I just realized there were <x>__Instance__outline materials, in my imported VRM character's folder. So, I can change some of the parameters per-material (e.g.: bUseDitherAlpha, DitherAlpha).

But other parameters (e.g.: mtoon_OutlineColor, mtoon_OutlineWidth) seem to be overridden by what's set in the MToonMaterialSystem's global parameters (e.g.: Outline Color Scale, Outline Width Scale), so I'm not able to change them per-material.

EDIT 1: After changing the mtoon_OutlineWidth value in the material instance, if I click Refresh in the MToonAttachActor parameters, the outline's width is correctly updated based on the material instance's parameter! šŸ˜„ Plus, it correctly follows Outline Width Scale from the MaterialSystem global parameters.

This should probably also work with other parameters that "don't auto-refresh" when we change their values. I still haven't managed to update the outline color directly from the material instance...

EDIT 2: To update the outline color per-material, I first needed to set the global Outline Color Scale to its default RGBA value (1, 1, 1, 0). Setting the Alpha value to 0 is very important.

Then, I was able to change mtoon_OutlineColor in the material instance and immediately see the new outline color in the level viewport. Also, setting the TexturePow material parameter to -1 helped me to get much closer colors to the ones I set in mtoon_OutlineColor. šŸ˜„

andreiagmu commented 5 months ago

Regarding question 3: I think this comment (from another issue) describes what I need to add to my character controller Blueprint. I'll try it out! https://github.com/ruyo/VRM4U/issues/87#issuecomment-903310553

EDIT: Based on the linked comment's instruction and screenshot, I managed to copy that AttachActor code region from BP_VrmModelActor to my character controller Blueprint. This added the outline and custom shadow map for my dynamically spawned character. šŸ˜„

Copying the code (and making it compile correctly) wasn't trivial, but it wasn't too hard to do.