Let $X$ be a projective variety over $\mathbb{C}$. Is there a way to define some number $\tilde{\chi}(X)\in \mathbb{Z}$ satisfying both of the following two properties?

$\boldsymbol{(1)} \;$ When $X$ is smooth, $\tilde{\chi}(X)=\chi(X)$, where $\chi(X)$ is the usual Euler number of $X$ (as a topological space).

$\boldsymbol{(2)} \;$ $\tilde{\chi}(X)$ is invariant under deformation, i.e. if we have a family of variety over a connected base $B$, then any two fibers have the same $\tilde{\chi}$.

If I consider an affine variety (still over $\mathbb{C}$) instead of a projective variety, then what is the answer to the corresponding question?