Is there any way to make a custom despawn for an entity?

I’m trying to find a way to make a certain entity despawn after a certain amount of time or when it hits a block

Continue to help post