Estimate the amount you need to set aside to achieve your goal and always keep separate savings available. Don’t invest if you don't have any back-up savings. In general, your back-up savings should equal about three to six months of wages. Set this money aside in a risk-free savings account so that it’s available immediately if you should need it. Most importantly, only use it in times of hardship (urgent car or home repairs, etc.). This will prevent you from liquidating investments and potentially losing money by doing so.
Don’t stick your head in the sand, either. Inflation is currently higher than the return on savings accounts and not investing, especially if you have the means, also involves a significant risk of capital erosion.
In short, keep a buffer for unforeseen events and short-term projects, and invest part of your capital for your longer-term projects.