Gamma-ray emission in active galaxies is expected to originate in a close priximity of the supermassive black hole surrounded by a reach cluster of luminous stars. We consider the effects of luminous stars crossing accidentally the gamma-ray beam close to the observer's
line of sight. We show that soft radiation of massive stars can create enough target for transient absorption of the gamma rays in multi-GeV to TeV energy range. Time-dependent effects on the gamma-ray spectra due to the encounter with stars are investigated. As an example, we consider such effects on the spectra observed from a typical blazar, 1ES 1959+650 (in an active state) and also in the case of a radio galaxy M87 (in a low state). Observation of such transient
characteristic features in the gamma-ray spectra of blazars and radio galaxies lays within the sensitivity of the future Cherenkov Telescope Array.