Good evening, @Darkcoder1,
I hope this message finds you well! I’m currently using the Paint in 3D addon for my project and have encountered an issue I’m unsure how to handle.
In my setup, I have a live enemy character that gets painted (i.e., injured) during gameplay. When the enemy dies, it’s destroyed and replaced with a ragdoll prefab. I’d like to transfer the painted material or texture from the live enemy to the ragdoll, so the paint effects remain consistent.
Both the enemy and the ragdoll share the same mesh and material. The main difference is that the ragdoll has AI logic removed and rigidbodies added. I’ve tried simply copying the material from the live enemy to the ragdoll, but the paint didn’t transfer.
Ideally, I’d like to copy the painted mesh or texture at runtime to the ragdoll to avoid modifying the existing enemy prefab(to activate the ragdoll from the live enemy directly), which is already complex and cluttered. Setting up ragdoll colliders and rigidbodies directly on the enemy prefab would be quite time-consuming.
Do you have any advice on how to achieve this? Any guidance would be greatly appreciated!
Thank you for your time and for creating such an great tool!
Edit: The “CwPaintableMeshTexture” doesn’t seem to have such method as “LoadData” in 4.1.3, was it removed or am i missing something? Tried to apply texture data to the ragdoll but the method, as described in “Can I save my in-game paint to my project?” section of the manual, is not there.
Edit 2: After banging my head against the keyboard a little bit more, i found the solution. I cache the ragdoll instantiation, then use that cached variable to get both components “CwPaintableMesh” and "CwPaintableMeshTexture. Then its a matter of assigning each parameter in code instead of manually editing the values of the two components in ragdoll, at last using Graphics.Blit to copy the pixel data from the source (Live enemy) to the destination (Ragdoll). Here’s the snippet:
// get paint data from live enemy
var srcPaintable = GetComponentInChildren<CwPaintableMesh>();
if (srcPaintable == null)
{
Debug.LogError("CwPaintable mesh is null");
return;
}
// instantiate ragdoll
GameObject ragdoll = Instantiate(ragdollPrefab, transform.position, transform.rotation);
// setup paint components on ragdoll
var dstPaintable = ragdoll.GetComponentInChildren<CwPaintableMesh>();
dstPaintable.MaterialApplication = srcPaintable.MaterialApplication;
dstPaintable.Activate();
// copy each paintable texture
foreach (var srcTexture in srcPaintable.PaintableTextures)
{
var dstTexture = ragdoll.GetComponentInChildren<CwPaintableMeshTexture>();
dstTexture.Slot = srcTexture.Slot;
dstTexture.Group = srcTexture.Group;
// copy the current render texture directly
Graphics.Blit(srcTexture.Current, dstTexture.Current);
}