Forum rules - please read before posting.

Camera effects

edited April 2014 in Technical Q&A
Hey again! From what I understood we have only one camera moving around to other cameras in the scen...but whaT if I want to use one camera effect for a single camera in the scene? I tried depht of field in one of the cameras and is not working :(
«1

Comments

  • What exactly did you do? What exactly happend? What does "is not working" mean in this case? If you provide so little information, it is impossible for the rest of us to help you.

    Again, please elaborate ...
  • Well...to be honest I think that was clear enough but I'll try to explain better...When I load the script for the depth of field on one of my cameras in the scene the camera with the script effect works normally but the image effect is not working... :((
  • The GameCameras you place down are for reference only - they never actually render.

    Any "effect" scripts you have will need to be added to the MainCamera prefab instead.
  • So if I want to add an effect like depth of field only to one camera I can't? For example I want the kitchen camera with depth of field but the bathroom camera normal
  • I think activating your effect when one camera becomes the "main" camera and deactivating it when some other becomes active should be possible. You would have to write a script for that activation/deactivation, though.
  • That's right - simple enough to do, you could even just have a script that has functions to enable and disable the entire "effect" component.  In C, this would be something like:

    void TurnOnEffect ()
    {
      this.GetComponent <MyEffect>().enabled = true;
    }


    void TurnOffEffect ()
    {
      this.GetComponent <MyEffect>().enabled = false;
    }

    Attach the script to your GameCamera, then use the Object: Send message Action to send the custom messages "TurnOnEffect" and "TurnOffEffect" as appropriate.
  • edited July 2014

    I have a situation in which I need different image effects on the Main Camera depending on which Game Camera is currently in effect. More so, in some cases, I would need the same image effect but with different values depending on which Game Camera is currently in effect. Doing this in code would
    be tedious for each and every camera switch in each and every scene.

    I thought a nice solution would be to let each Game Camera store its own components and values and on Camera Switch, the Main Camera would copy unto itself all components and values belonging to the Game Camera  it is switching to, in much the same way it copies its position, rotation and field of view.

    Would you be willing to consider incorporating such behavior into AC, Chris, or should I go about implementing this in my own code?


  • Do you mean literally copying the attached GameCamera's script components?
  • Yes, that's what I meant. The idea is to let the main camera become everything the game camera wanted upon camera switch instead of just copying a few parameters.

    What do you think?
  • Copying select parameters is an essential part of the MainCamera script, since it needs to handle other things besides.

    Copying over "new" components (such as custom scripts) would be useful, I agree, but with it brings the problem of losing them again when resetting / moving to another camera, and not removing any custom scripts the user might have added to the MainCamera prefab separately.
  • When I thought of coding this myself, I made the decision that the Main Camera should never have script components of its own (except the MainCamera script of course). The only script components that will be in effect at any given moment in the Main Camera will be those copied from the Game Camera. Once we switch to another Game Camera, we remove from the Main Camera all script components (again, except the MainCamera script) and copy the ones from the new Game Camera. Well, that's roughly what I had in mind.
  • edited August 2014
    Good thinking, but there is the added problem of those who wish to have other components on their MainCamera (either instead of, or as well as, GameCameras).  An "official" AC solution would therefore have to be much more complex than a custom-made one, since it'd have to account for each and any way it'd be used.

    (Incidentally, is it even possible to copy a component - with values - in-game?)
  • I understand what you're saying but what are the pros of having components on the Main Camera in addition to those in Game Cameras? So that you can put there components you want all Game Cameras to share? If that's the only reasoning, I don't think it's a very strong one. I mean, it's nice to have, but not much more than this, the way I see it. In much the same way you are now completely ignoring components in Game Cameras, you can do the same in the future for the Main Camera components. The manual can state this very clearly that all Main Camera components are ignored.

    As for the technicalities, Unity only offers the ability to add "empty" components to a game object (using GameObject.AddComponent()) but you can enumerate the components in a Game Camera object, create "empty" ones of the same types in the Main Camera and then use reflection to copy the fields of each component from the source to the target. Take a look at this.
  • Thanks for the link.

    The main reason I brought up the issue of components already on the MainCamera is that, without this feature, this is what other users have resorted to.  It's not so much a case of best practices, and more about making sure it doesn't mess things up for anyone else!

    I could imagine, also, that having intensive post-image effect scripts on every GameCamera would cause needless performance issues, whether their associated Camera component is active or not.  If you wanted to add a simple DOF script, you shouldn't have to add it to every GameCamera - the MainCamera should be enough.
  • If having intensive post-image effect scripts on every Game Camera really causes performance issues, they should be disabled when on the Game Cameras and the code will enable them after copying them to the Main Camera. But why would a disabled script have a hit on performance?

    As for having one single place to put components that are common to all Game Cameras, well, that's nice, of course, but you don't usually have such thing at all (in other systems). You just have to set up each and every camera the way you want it - which is perfectly reasonable, the way I see it. And if you do want to keep this commodity, you can come up with a new type of dummy camera (much like the Game Camera) that would be called something like Common Camera, that will hold all components the user wishes all cameras to have. So when the camera is switched, all components from the Common Camera would be copied to the Main Camera just as those of the target Game Camera would.

    As for not wanting to break existing games, it won't be the first time an update comes out with an explanation what needs to be taken care of when upgrading. Otherwise, you may end up not improving certain aspects of the toolkit as to not mess with existing projects, or ending up improving but also keeping the previous behavior intact somehow, based on some setting - something that ultimately causes your code to be rather confusing.

    Anyway, I'm just answering your concerns, I'm not trying to convince you to actually implement this behavior. Just let me know so that I will know whether to implement this myself or not. :)

    Thanks.

  • The Common Camera suggestion is exactly what you needed to make, that's an excellent idea.

    It's a complex area to be sure, so I won't make promises, but will look into it.
  • Thanks!

    I'll wait with coding my own implementation then. :)
  • edited June 2015
    Hello, anyone found a solution for this?
    I would also love to have a generic main-cam that copies properties from the scene camera it takes place of, clears itself when changing camera and copies the value of the new cam.

    Edit* might be a solution to have a "copy camera components\properties" and a "clear camera components\properties" nodes to use in cutscenes.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.