Can't turn material of SkinMeshRenderer list back to normal after animation.

Hello everyone,

I’ve having trouble figuring out where is my mistake in my code. I’ve been trying to do something similar to the warp in this video : Recreating Final Fantasy XV's Warp Strike | Mix and Jam - YouTube

The main difference being that my playerCharacter is warped to the position of the last bullet it fired using DOTween’s DOMove method.

But I can’t turn my skinnedmesh list material back to normal after my warp is done.
Moreover, it seems that my animator component is somehow disabled during the cooldown of my warp ability.

I’ve trying moving the “skinnedmeshrenderer list” here and there but it either changes nothing or doesn’t change the material to the glow one when warping.

Here’s the code I’m working on :

//This is the part in the Update function.

    //Blinking
    if (Input.GetKeyDown(KeyCode.Space))
    {
        if (!warpOnCD && nbBullets.Count > 0)
            Blink();
    }

//And here are my methods

public void Blink()

{
    int last;
    last = nbBullets.Count - 1;
    GameObject lastBullet = nbBullets[last];

    GameObject clone = Instantiate(gameObject, transform.position, transform.rotation);
    Destroy(clone.GetComponent<Animator>());
    Destroy(clone.GetComponent<Player>());
    Destroy(clone.GetComponent<Rigidbody>());
    Destroy(clone.GetComponent<CapsuleCollider>());

    SkinnedMeshRenderer[] skinMeshList = GetComponentsInChildren<SkinnedMeshRenderer>();
    foreach (SkinnedMeshRenderer smr in skinMeshList)
    {
        Debug.Log("GHOST");
        smr.material = glowMaterial;
    }

    transform.DOMove(lastBullet.transform.position - new Vector3(0, 1.5f, 0), warpDuration);
    Destroy(lastBullet);
    nbBullets.Clear();

  
    StartCoroutine("WarpCD");
    }

IEnumerator WarpCD()
{

    warpOnCD = true;
    animator.SetBool("Warping", true);
    Debug.Log("Warp on CD...");
    yield return new WaitForSeconds(5);

    warpOnCD = false;
    animator.SetBool("Warping", false);

    SkinnedMeshRenderer[] skinMeshList2 = GetComponentsInChildren<SkinnedMeshRenderer>();
    foreach (SkinnedMeshRenderer smr2 in skinMeshList2)
    {
        Debug.Log("IDLE");
        smr2.material = idleMaterial;
    }

}

What is happening with this code :

  • My character creates a clone with “IDLE” material
  • Jumps to last position with “GLOW Material” on.
  • Stays on “GLOW Material” during the cooldown + animator is disabled.
  • Goes back to “IDLE” material and animator enabled at the end of the cooldown.
  • List item

I’d be glad to have some help, knowledge and tips on how to do what I’m trying to do.

Hello @Dan-Dylan,
:

  • regarding animations you are setting “Warping” to True for 5 seconds so if you want the animation to last only for the animation time, be sure to have a transition from your warping animation to idle/some default state with no conditions set but “has exit time”=true.
  • for the SkinMeshRenderer, depending how you defined your new meshes, you might want to instantiate & add bones fitting, for ex

Option 0 : Change material only (which is what you seem to seek)
Be careful here if your meshes has several materials you need to address it 1 by 1
Refer to : renderer.materials not working. - Questions & Answers - Unity Discussions

Option 1 : change mesh only

Mesh newMesh= Instantiate(inNewMesh) as Mesh;
GetComponent<SkinnedMeshRenderer>().sharedMesh = newMesh;

Option 2 : Insert the corresponding mesh & fit bones

if (newItem.mesh != null) { 
            SkinnedMeshRenderer newMesh = Instantiate<SkinnedMeshRenderer>(newItem.mesh);
            newMesh.transform.parent = targetMesh.transform;
            newMesh.bones = targetMesh.bones;
            newMesh.rootBone = targetMesh.rootBone;
            
// Delete
            Destroy(newMesh.gameObject);
        }