If () returns null it means object or world it self is not fully initiated at point it’s being called, i suspect you place it in constructor in which that usually happens, so you need to place it in some event function when everything is ready.
A UObject does not know inherently what world it belongs to. The purpose of the function is for that Object to be able to let others know which World it is in. Actors do this via their Level reference and Components do this either via their Actor owner or the World they’ve been registered with. Each other Object type has to find its own path back to World, often through a reference to an Actor.
If you want to be able to call on your class, you need to override the function and provide a valid path to a World.