BuddyPress and namespacing

Try using if ( class_exists( '\BP_Attachment', false ) )?

Could be that you need to tell PHP that the class is in the global namespace