Knocking sound when idle

When I am at a stop light waiting for the light to turn I hear a knocking sound coming from the engine area. If I move the car into neutral it disappears, and it mostly occurs when the car is idle, but sometimes it occurs while I’m driving. What in the world could this be?!

Could be just something loose and rattling.
Get a helper to put the car in gear and hold it in place then listen from outside (hood open) where the sound is coming from.