The problem you’ve having here is that you’re using the constructor. The variable, in the constructor, IS null, unless you set it in the constructor (which you should, to null - you should always initialise variables.)
To fix your problem, you need to move the SetMaterial line to a different function. Override either PostInitProperties (which is run after bp props have been loaded, I believe) or PostInitializeComponents and set the material there. Or OnConstruct as somebody else said.
You probably want to add a UPROPERTY variable for your sphere, too, if you haven’t, so you can easily access it in the other method.
THANK YOU, this is exactly what I was facing. For any future Googlers, this is relevant to everything, including assigning a StaticMesh to your StaticMeshComponent programmatically