[RPG] Can a spell be readied to trigger when its intended target comes into view

dnd-5ereadied-actionspellstargeting

Can I ready witch bolt, for instance, with the condition of attacking "the first goblin to come out of the cave" if I cannot see the goblin at the time of my (Ready) action? To be perfectly clear: at the time of the Ready action, the goblin is around a corner, in darkness: not targetable by witch bolt.

On the one hand: the Ready action states that (PHB p.193)

when you ready a spell, you cast it as normal but hold its energy…."

Part of casting a spell is targeting (inferred from "Targeting" as a sub-heading under "Casting a Spell", PHB pp.202-204).

You can't target something that you can't see, so it would seem that since you can't target the goblin at the time of the Ready action you can't cast the spell in the first place.

On the other hand: isn't this use of "Ready" the same as the "I'll attack the first goblin to come out of the cave" that is the classic use-case for Ready? Picking a target is part of the Attack action, after all.

Best Answer

Yes.

Your inference, that Targeting is part of Casting and therefore can't be done at time of effect, is a little tenuous. And, given the examples for readying a spell, it seems likely that the intent is to let you target it on release:

When you ready a spell, you cast it as normal but hold its energy, which you release with your reaction when the trigger occurs. [...] For example, if you are concentrating on the web spell and ready magic missile, your web spell ends, and if you take damage before you release magic missile with your reaction, your concentration might be broken.

Magic Missile targets a creature. The most likely reason for readying it rather than casting it immediately, is that the target isn't yet targetable. Once it steps through the doorway, or whatever the trigger was, then it becomes a valid target, and ends up on the receiving end of your Magic Missile.

This is confirmed by Sage Advice, Rules Answers: June 2016

For readying a spell or other action, does the target have to be in range?

Your target must be within range when you take a readied action, not when you first ready it.

(emphasis mine)