- Home /
iTween CameraFade not working in some cases (related to camera's cullingMask)
Hello,
I'm at a loss here...
What I'm trying to do
Animate the fading from one camera to another (in the same scene), with iTween (v2.0.43) and Unity Pro 3.3.
How I'm doing it
- I create a Texture2D, which contains the current view snapshot.
- I assign it to iTween using iTween.CameraFadeAdd( tex_fadeFrom ).
- I change the active camera to the new one I wish to use.
- I start the tween.
Code is here (I'm not writing the code I use to take a Texture2D snapshot of the view, because the problem is not there: it's working perfectly):
// Here I store the current camera snapshot.
// tex_fadeFrom is a private property.
// HVCameraUtils.getViewScreenshot is the method
// that creates the Texture2D from the current view.
tex_fadeFrom = HVCameraUtils.GetViewScreenshot();
// This calls a setter which changes
// the main camera to the one I wish to fade to.
Vars.activeCam = Vars.isolationCam;
// iTween.
iTween.CameraFadeAdd( tex_fadeFrom );
Hashtable tw = new Hashtable();
tw.Add( "amount", 1 );
tw.Add( "time", 0.7f );
tw.Add( "oncomplete", "Isolate_fadeComplete" );
tw.Add( "oncompletetarget", this.gameObject );
iTween.CameraFadeFrom( tw );
The problem
All works perfectly, until I change the culling mask (via the camera's Inspector) of the secondary camera (isolationCam).
If the culling mask contains some of Unity's default layers, the animation plays correctly. Otherwise (like in this case, in which the culling mask is set to layer 30 alone), the cameras switch correctly, but the fade animation doesn't play (tex_fadeFrom never appears and fades out: simply put, the secondary camera appears immediately). Or better: I can see the animation in the scene view (!), where tex_fadeFrom appears and fades out, but not in the game view.
Please help! :P
Answer by Thom Denick · Jan 14, 2012 at 07:35 PM
I know this is a pretty old question, but I just ran into this problem and resolved it. Basically when iTween creates its camera Fade Texture, it puts it on the "Default" layer. So if your Camera is culling out "Default" you won't see the fade. You can see this pausing your game while it is running in the editor and look for the iTween Camera Fade Object.
Unfortunately, it doesn't seem as though Mr. Berkebile programmed a way to easily change the Layer of the texture (just the depth). As such there isn't an easy way to get a reference to the object and change it's layer. I just added Default to the masks on my cameras as I don't really have anything important sitting in that layer anyway. I would imagine you could also search for the object's name: "iTween Camera Fade" and get a reference that way.
Update After realizing I do indeed have objects on my default layer, I went back and coded it as described above. Here's the code solution as I have it:
private void Awake() {
iTween.CameraFadeAdd (LoadingTexture, 5000);
findAndChangeCameraFadeObjectLayer();
}
private void findAndChangeCameraFadeObjectLayer() {
GameObject cameraFadeObject = GameObject.Find ("iTween Camera Fade");
if(cameraFadeObject)
cameraFadeObject.layer = 16;
}
Thanks a lot Smorpheus. Actually, I ended up fading the camera without iTween - it was the first step towards what's now HOTween: my egotistical tween engine (http://hotween.holoville.com, if you're curious - though there's no direct "cameraFade" method, I just created snapshots and tweened some field).
Awesome, iTween frequently frustrates me. I'll take a look at your package on my next project. Are you going to post it in the Asset Store?
I'll post it in the Asset Store within the end of the month, I suppose. And I just made it open-source via Google Code (http://code.google.com/p/hotween). Though I have to note that it's not a "better" engine than iTween: it's simply very different and truly object-oriented (and type-safe), and definitely suits more my coding tastes :)
Yes, well I'm not particularly a fan of the Hash system. So if it's OO && type-safe that's probably good enough for me to switch. :) I much prefer the TweenParms object just for sanity. Also the Google Code URL is bad.
Oops, sorry, the comment took hold of the last parenthesis and added it to the url :P Here it is again: http://code.google.com/p/hotween
And glad you like TweenParms: I tested and implemnted a lot (uh, not that lot: 2 other) of alternative ways, before finally deciding for that :)
Answer by ChiuanWei · Aug 19, 2011 at 12:38 AM
because the Texture2D u Get ,base on that culling mask.when your culling mask is set to layer 30 alone. Texture2D is nothing, so .you can't see anything~~
Answer by netlander · Jul 26, 2013 at 06:26 PM
I have a similar problem where iTween.CameraFadeTo works for a while then it stops fading for no apparent reason, this happened twice on two different projects when all of a sudden fading stop occurring.
My code is very simple, no culling masks involved.
// First I setup the fade
void Start () {
iTween.CameraFadeAdd(fadingScreen, 99999);
}
// Then I do the fade (in a different method)
iTween.CameraFadeTo(iTween.Hash...));
It works for a while then out of the blue kaboom!
After looking at the "iTween Camera Fade" I noticed that when the fade works the GUITexture contains the fadingScreen. In the case when it's not working the GUITexture is empty.
Why would the "iTween Camera Fade" loose the fadingScreen I setup or even the default one without any reason? Could it be a bug?
Any help is much appreciated. Paul
Your answer
Follow this Question
Related Questions
How to Fade out a Rocketbox avatar (using iTween)? 0 Answers
iTween FadeTo() problem 1 Answer
Is there any way to use "from" value and "to" value in a single iTween call ? 2 Answers
iTween FadeTo 1 Answer
How to best optimise this script 1 Answer