Limiting things the camera can see in 2D

I’m creating a platformer in 2D and I don’t want the camera to show black void when the player goes all the way to the left or right of the level and that’s what happens since the camera is centered on the player. How can I prevent it from doing this? In other words, how can I prevent the camera from seeing things past given points so that only things being over the background can be seen even if the player reaches one of the edges of the level?

You could extend the background past camera view, or you could also use camera blocking volumes, though I’m not quite versed in using those.

The problem is I can’t really extend the background cause it’s not a repetitive one - everything takes place inside a mansion and it only makes sense if you can see what is currently inside the rooms.

There may be a more elegant way to do this, but like dotdog20 said I would try blocking volumes to keep the camera from traveling further than the edge. The trick is going to be placing the blocking volumes so that they stop the camera at just the right spot, so that its edges correspond to the edges of your map. You could run into problems though if the length of your spring arm is too low and you run through environment elements. I tried using blocking volumes on the top down template really quickly and it worked. With tweaking it would be a solution. You just have to make sure that you turn on collision for the camera in the character blueprint. If you are using the template top down character it is turned off by default.
227ad909a6f7a03e3f0ea960fac20c7f4f4bce68.jpeg