Download

[Resolved] making an object visible to only a certain camera

hey,
I’m trying to make a practice game where the player can hold a camera and through that camera he can see certain stuff the he can’t see with his own eye, i got everything set up using a “scene capture 2D” camera. but how do i make an object only visible to this camera ?

if it’s not possible to do in blueprints, can you give me a step by step tutorial of how to do that in code (because i’v less than 1% experience with code)

thanks in advance

Is there possibility to see that object trough camera on normal way at same time? Or when player switches to camera he/she has only camera view?
Because how to make object visible trough camera and not visible without camera on same picture, for this i have no idea.

For hidding/showing objects in runtime there is easy solution: you can set visibility of objects. However shadows and static lighting on such objects can be messed up.

To show/hide stuff in your case:

  • make blueprint that can contain object (for eg. child actor, or mesh)
  • make blueprint interface that says “camera mode aware” or something like this
  • add that blueprint interface to all objects that can hide/show
  • in that interface functions in those objects add logic to show/hide (toggle visibility) or show hide depending on boolean variable etc.
  • in player pawn or player controller do: “foreachactor with interface” then cast to your blueprint object type and tell them to show/hide
  • do that foreach loop every time player switches to camera/from camera.

This is best solution for your case, or rather its most resource friendly.

Another solution is to make event dispatcher in player pawn or controller that has visibility variable, then bind to that dispatcher from every object blueprint and show/hide stuff in them.
Works almost like above loop, it just looks more ugly with all that binding.

thank you for the reply, unfortunately when the player is looking through the camera, the camera view is about 75% of the player view, so i need the object to render in the “scene capture 2d” camera and not in the player camera.

if that is not possible, a different approach can be like this, when looking through the camera the real player view is visible only on the sides of the screen, so if i’m looking at the object from certain degrees while looking through the camera , then the object will appear.

so how can i set the player viewing angle as a condition ?

using a “box trace” i almost got it working, though i’m having trouble getting the trace box size to change depending on the distance between the player and the object

ok so i got it working, but in a very ugly way, using the box trace and some manual calculations to change the box trace size depending on the distance, if anyone want’s to know how to do it, ask me, as it’s too much trouble to break down.

Hi, Vampire737 can you please explain me that.

And what if you spawn it since you put the camera in some range in front of you while the animation is executing… camera on, objetct spawned, camera off object destroyed.

greetings

still waiting for explanation on this render hack…

hey everyone
First of all I want to sincerely apologize to everyone who asked for the method used, and i’m sorry i took literally years to respond, I ended up abandoning this project and was inactive on these forums for a long time, that’s way I only just saw your comments.

i dug up the files and below I tried my best to break down my method for doing this, though i still think it’s a rather ugly solution and will probably not work in most cases
also i made it ages ago and i was a lot less knowledgeable in coding and unreal engine in general, but here goes:

the system i was trying to do was a camera that the player holds that can see certain objects that the player can’t see, to achieve that i used a 2nd camera component in the player character with a Render target texture used in a material set to a screen, i attached a video to show the effect below:

to achieve the illusion of the objects only appearing in the camera feed I used the fact that the camera the player is holding is blocking most of their view, thus by creating a box trace from the camera with a set half size i can hide the object when it’s to far to the edge of the screen, making it disappear when the player is looking it from the edge of their view around the camera, by varying the half size based on the object distance I kept the illusion from failing when the player became closer or farther away from the object.

below i attached several screenshots breaking down the blueprint:


here I had 2 objects and needed to check that both are closer than the maximum distance i manually set before


this chooses the object that is within range and set the “distance to object” variable to the distance between it and the camera, the code works by focusing on only one object at a time sort of, because it needs to change the half size depending on the distance, in the level i had the 2 objects placed at 2 different places so that they don’t intersect with each other.

these all then run the box trace and below is what i connected to it:

03.JPG
these connect to the “start” location input and the “orientation” input in the box trace


this takes the location of a point directly infront of the camera by a certain pre-set distance (which is the maximum view distance), this connects to the “End” Input on the box trace


this calculates the half size based on the distance to the object, and below i explain the variables above


the 6 variables on the left are pre-set variables:

  • “Farthest Distance For Object Vis” and “Nearest Distance For Object Vis” are distance limits i placed for the object visibility, so the object’s distance from the camera must be between these 2 values for it to become visible.
  • “Trace Y Far” and “Trace Z Far” are the value for y and z of the half size input on the box trace that guaranty the object disappears when it’s not in the 2nd camera view, when it’s exactly at the maximum distance mentioned above, I had to manually figure out these values through trial and error.
  • “Trace Y Near” and “Trace Z Near” are the same as the above 2 variables but when the object is at minimum distance allowed.

then i can calculate the “Y Value Change Rate” and the “Z Value Change Rate” as above.
these values are all pre set, and the above blueprint is just for explanation.


all the above calculations feed in the box Trace and then check for further extra conditions to then finally check if the object should be visible or not


a close up for the extra conditions. (the distance checks here might be redundant, but i add them to make sure that the objects disappears at these distances)

Below is a video showing the effect:

sorry for not reponding, here the explaination above