Hello, I want to make a weapon image change system in Unreal without using skins, to give more flexibility in the game engine. Does the API provide some function like that? If not, what is the best way to do it and which part of plugin code should I look into?
UE5 Replace part of Atlas image with custom image
- Modifié
Currently, that's not possible out of the box with the available C++ and blueprint API we expose. The problem is that the SkeletonRendererComponent
, a subclass of ProceduralMesh
, composes meshes on the fly, using the materials associated with atlas pages set on the SkeletonAnimationComponent
. See the implementation here:
https://github.com/EsotericSoftware/spine-runtimes/blob/4.1/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineSkeletonRendererComponent.cpp#L273
SkeletonRendererComponent
would have to be extended so you can set your own material instances for a specific slot. The API would probably look something like SkeletonRendererComponent::SetSlotMaterial(FString SlotName, UMaterialInstanceDynamic *Material, TArray<FVector2D> &Uvs)
. The renderer would store the material instance and associated texture coordinates for that slot name.
When a slot's attachment is renderered in SkeletonRendererComponent::UpdateMesh()
, we'd check if a custom material and UV set were set for that specific slot and use that instead of the material and UVs fetched from the slot's attachment (see https://github.com/EsotericSoftware/spine-runtimes/blob/4.1/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineSkeletonRendererComponent.cpp#L240 for where we fetch the atlas page (material) and UVs from the attachment).
All of this is pretty involved and error prone. For one, the material instance set via SetSlotMaterial()
would have to be properly managed regarding the UE garbage collector. Also, having the API user generate texture coordinates for attachments is non-trivial.
We currently have no short or mid term plan to implement this functionality I'm afraid, exactly because it is so involved and error prone.
Thank you very much for the reply. I'll stick to using skins for now.
There is one additional question related to rendering on the graphics side.
When using TAA or TSR anti-aliasing together with perspective camera, the moving part of rendered mesh is very blurry. Switching material from translucent to masked of the render component doesn't help with the problem. All motion blur in my camera and post processing are disabled. Using masked material used to solve similar issue with other mesh or UI rendering.
My current walk around is using FXAA, which makes background sprites not as sharp.
Not sure if this question is more on the engine side, but it would be nice if dev can give some insight to it.
I'm sadly not very familiar with UE's TAA/TSR anti-aliasing, so it's hard for me to tell what might be the issue here. The SkeletonRendererComponent
is a subclass of UE's ProceduralMesh
, which might be a hint. You could try to search for solutions to this problem for ProceduralMesh
which should apply to the SkeletonRendererComponent
as well.
Thanks, that's good enough for a direction.