Gets the attached entity by ID.
The ID of the attached entity if successful, or a null pointer otherwise.