0

I'm using the FadeObjectInOut script from the wiki (http://wiki.unity3d.com/index.php/FadeObjectInOut)

It's attached to two different objects (each), which trigger indiviudally. It'll resolve in

IndexOutOfRangeException: Array index is out of range.
FadeObjectIO.SetNewColor (UnityEngine.Renderer[] rendererObjects, Int32 i) (at Assets/Scripts/FadeObjectIO.cs:132)

It reffers to the line

Color newColor = (colors != null ? colors[i] : rendererObjects[i].material.color);

..., which tried to export as an function and still calls the same error. The whole code snippet relies on IEnumerator.

Due to the fact, that this only happens every now and then, I'm totally confused. I can't provoke it by triggering the events at the same time, I can't provok it by flashing between fadeOut and unIn super fast.

As solution, I tried things from the internet and also the "How to Avoid" of this question: What is an IndexOutOfRangeException / ArgumentOutOfRangeException and how do I fix it?

The last time, I triggered my oculus trigger on/off in high frequency and nothing happend. Frustrated I wanted to take the headset off and as I put down my controllers, it crashed again. (It's on the Touch trigger and thereby easily fast triggerable.)

I can't help myself anymore... Thanks for any advise

.

EDIT: below the thrown error + the debug code. After fading out, the Renderers are getting enabled=false. Since we are in a while loop, it doesnt really make sense to me tho, that the dot might've been already faded out (and it's renderer therby deactivated) being an error for the array - because it doesnt get any changes. Hmmmm.

Debug everything

Edit: new state

Flo
  • 97
  • 10
  • I think you should check first there are child gameobjects which have `Renderer` as a component. – Heejae Kim Feb 24 '19 at 00:51
  • It’s a laser containing a line renderer and a sphere. Both of them have do have constantly line renderer. But I’ll deactivate them if they faded out completely. I’ll put in an if, to see if that solves the issue. Tho, I did place a Debug.Log(rendererObjects.length) in there - which always throws 1 or 2 (depending on for loop, both once per frame) but never 0. – Flo Feb 24 '19 at 07:47
  • @HeejaeKim, edited question - do you think that's the cause? – Flo Feb 24 '19 at 10:51
  • You'd better to check about `colors` like `Debug.Log("colors len = " + colors.Lenght);`. And, because `colors` is a global variable, you should also check there is no line to refer/assign to this variable. – Heejae Kim Feb 24 '19 at 12:12
  • @HeejaeKim, it passes an array length of 1. But everytime - regardless of crash or normal behavior. And as before, it crashes at the call of colors[i] in `Debug.Log(colors[i]); – Flo Feb 24 '19 at 13:26
  • You mean `colors.Length` is 1? And when I see [Debug everything](https://i.stack.imgur.com/abLyY.png), `rendererObjects.Length` is 2, right? – Heejae Kim Feb 24 '19 at 13:54
  • @HeejaeKim my bad! Still had an enable=false state in there. Color array = 2 is true. ... now all the time. Almost. I end up with getting the attached console code. Since that I did a minor adjustment to the rest - I’ll let you know, if that fixed it! (Error occurs only occasionally) – Flo Feb 24 '19 at 14:17

0 Answers0