4. If the equation $\sin ^{2} x+\sin 2 x=m+2 \cos ^{2} x$ has real solutions, then the range of real number $m$ is
4. $\left[\frac{-1-\sqrt{13}}{2}, \frac{-1+\sqrt{13}}{2}\right]$.
$m=\frac{1-\cos 2 x}{2}+\sin 2 x-(1+\cos 2 x)=-\frac{1}{2}+\frac{\sqrt{13}}{2} \sin (2 x+\varphi), \varphi=-\arctan \frac{3}{2}$, so when $m \in\left[-\frac{1}{2}-\frac{\sqrt{13}}{2},-\frac{1}{2}+\frac{\sqrt{13}}{2}\right]$, the equation has real solutions.