Yes, but do it methodically. To substitute the recommended yarn, first compare the fibre content, weight category, yardage per ball and 10×10 cm tension swatch. Choose a yarn with similar behaviour in drape, elasticity and stitch definition (for example, mercerised cotton for amigurumi, medium-twist wool for cables). Make a swatch in the pattern stitch, wash/block it and adjust the needle or hook size until you match the tension. Calculate the total yardage required by the pattern and buy with a 10–15% extra to avoid running short.
Keep the type of project in mind. For amigurumi, the finished size will change if you alter yarn weight; prioritise non-elastic yarns and use a slightly smaller hook than stated for a firm fabric (also adjust safety eye size and filling amount). For garments, choose yarns with similar behaviour after blocking; if you don’t reach gauge, consider making a different size. Although the safest option is to use the yarn suggested by the designer and brand, substitution works well if you follow these steps and always validate with a swatch.