Paper2D Flipbook leaves behind a sprite on changing flipbook

I’ve been implementing Flipbooks from Paper2D to show animations of my character in a 3D world with 2D graphics. What I’m trying to acheive is my walking animation to play when I walk forwards, and my idle animation to play when no movement keys are held. Currently doing that through a bit of bulky code that looks like this:



void UPlayerAnimationController::UpdateAnimation()
{
   m_CurrentAnimation->bVisible = false;

    // If idle, use one of our idle animations
    if (m_IsIdle)
    {
        switch (m_CurrentDirection)
        {
        case EDirection::Forwards:
            m_CurrentAnimation = m_IdleForwards;
            break;
        case EDirection::Backwards:
            m_CurrentAnimation = m_IdleBackwards;
            break;
        case EDirection::Left:
            m_CurrentAnimation = m_IdleLeft;
            break;
        case EDirection::Right:
            m_CurrentAnimation = m_IdleRight;
            break;
        default:
            UE_LOG(LogTemp, Fatal, TEXT("Somehow, we've not got a direction which we should be updating to. This is bad."));
            return;
        }

    }
    // If not idle, assume we're looking for a walking animation
    else
    {
        switch (m_CurrentDirection)
        {
        case EDirection::Forwards:
            m_CurrentAnimation = m_WalkForwards;
            break;
        case EDirection::Backwards:
            m_CurrentAnimation = m_WalkBackwards;
            break;
        case EDirection::Left:
            m_CurrentAnimation = m_WalkLeft;
            break;
        case EDirection::Right:
            m_CurrentAnimation = m_WalkRight;
            break;
        default:
            UE_LOG(LogTemp, Fatal, TEXT("Somehow, we've not got a direction which we should be updating to. This is bad."));
            return;
        }
    }
    m_CurrentAnimation->bVisible = true;
}


Before using the above code, I have loaded all the flipbooks required for my animation at load time in UFlipbookComponent variables, I set all the the bVisible property of all UFlipbookComponents to false, then I point the m_CurrentAnimation pointer to the flipbook I want to use, and set the m_CurrentAnimation to be visible.

The issue I’m facing is that whenever the animation changes, a sprite (the keyframe that was being played on the animation as it is stopped) will persist in the world, even though bVisible is set to false before changing the current animation pointer to point at a different animation.

My only thoughts on what is causing this are that flipbooks may work by creating and destroying sprites, by me changing the animation it is somehow not destroying the sprite? If anyone has any more information I can read on this or proposed solutions it would be much appreciated!

One workaround which I’ve found for this is to simply set the texture to have an alpha of 0. This isn’t a fix but does serve as a workaround, as I believe UE4 will still attempt to render the sprites with an alpha of 0, and it will have some impact on performance.

If anyone needs to know how to do this, it’s like so:


// Set to be transparent
    FLinearColor spriteColour = { 1.0f , 1.0f, 1.0f, 0.0f };
    m_CurrentAnimation->SetSpriteColor(spriteColour);

// Change the animation to the new one here

// Set to be opaque
    spriteColour = FLinearColor{ 1.0f , 1.0f, 1.0f, 1.0f };
    m_CurrentAnimation->SetSpriteColor(spriteColour);