- Home /
How to switch between variations of the same image effect, or save image effect settings?
I am using an advanced color correction image effect with curves set to particular settings.
I'd like to either be able to attach multiple instances of the image effect to the camera and enable and disable them with a script, or save and reload the curves to and from a variable set.
I haven't seen any obvious ways to reference multiple effects on the same camera. Can I define image effects on different game objects/prefabs and then point the camera to them at runtime? Or copy their contents?
Answer by Herman-Tulleken · Nov 16, 2010 at 09:44 AM
For separate effects you could call GetComponent(WhateverImageEffect)
on the camera, then use the enabled
property of the component to activate and deactive it.
For instances of the same effect, you could add all the components in your own array, and then use the objects in the array:
WhateverImageEffect[] effects; WhateverImageEffect currentEffect;
public void Start() { effects = GetComponents<WhateverImageEffect>(); currentEffect = effects[0]; currentEffect.enabled = true; //assumes all effects are deactivated on startup.
}
public void SetEffect(int effectIndex) { currentEffect.enabled = false; currentEffect = effects[effectIndex]; }
If you need the order to be the same between runs guaranteed, you could implement your own image effect class, extended from the original, with an extra ID field included. You can then use this to map the effects:
WhateverImageEffectWithID[] effects; WhateverImageEffectWithID currentEffect;
public void Start() { WhateverImageEffectWithID[] tmpEffects = GetComponents<WhateverImageEffectWithID>(); effects = new WhateverImageEffectWithID[tmpEffects .Length];
foreach(WhateverImageEffectWithID effect in tmpEffects ) { effects[effect.ID] = effect; }
currentEffect = effects[0]; currentEffect.enabled = true;
}
public void SetEffect(int effectID) { currentEffect.enabled = false; currentEffect = effects[effectID]; }
For this scheme, the IDs must be assigned by hand (from 0 up to some integer) in the inspector.
Thanks Herman. $$anonymous$$y situation is that I would have multiple instances of the same image effect. So I probably will have to create an array structure to contain them, and then enable or disable the desired one. I also looked at saving particular settings of the Color Correction Curves filter in a separate object, and then swapping them in and out.
@DocSWAB O$$anonymous$$, cool, now I understand. Do you think the order of the objects in GetComponents (the plural) can be relied on? If so, that should be a solution.
Probably have to have a separate GO with an array of image effect scripts, and then point one of those to the one on the camera to be the active one (or something like that). You're right in pointing out that you can't count on the order of GetComponents.
Here is another idea: Extend your own class from the image effect you want to use, and ad an ID field. You can then use this to track the right component in GetComponents (you could do the mapping on Start, in a separate array that you can user for lookups afterwards).
Now that I think about it, if you just use an array on start, you don't need an ID. I'll amend my answer to explain.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Camera Noise Effect Causing Black Screen? 0 Answers
Camera follow help? 1 Answer
Minimap clicking RTS style feature 3 Answers
camera focus on sphere 1 Answer