Xcode Not Found

When I try to run Unreal Engine 5.4.1 on my Mac Mini M2, I get this error:

Unreal Engine requires Xcode to compile shaders for Metal. To continue, install Xcode and open it to accept the license agreement. If you install Xcode to any location other than Applications/Xcode, also run the xcode-select command-line tool to specify its location.

I have downloaded xcode from the apple mac app store and accepted the license agreements.

How do I fix this?