Texture Swap Animator from WiKi does not execute on play

Hello to all. I have tried to use the Texture Swap Animator from Wiki, (see here) and it was working ok, both on Unity play, or on testing device.

Suddently the script stoped exucuting. I have tried it on a new scene, on a new GameObject, still no good at all.

What is more, whatever script I have tried in Unity3d (free) for texture swapping as animation, that is posted in the forum, I still get no response at all.

Is this a Unity bug, or something else is happening?

Has anyone came uppon the same problem, and what might be a woriking solution?

Need to have a texture animated in my project.

Thank you all in advance for your answers.

EDIT1

I have tried to add a debug.log as Dantus suggested and I get the message at console that "“Update was executed.14.39214
UnityEngine.Debug:Log(Object)
TextureSwapAnimator:Update() (at Assets/Standard Assets/Scripts/General Scripts/TextureSwapAnimator.js”.

I believe that there is nothing wrong with the script as I get the same message at my new project with a testing scene, where the texture animation is visible on Unity’s play.

I have tried to make a prefab, out of the GameObject that the script is working o.k. at my new project testing scene.

Then I have this prefab inserted to my initial project in order to get it animating. I thought that a prefab, would be a solution to my problem, but unfotunately, I get no visual of the texture animation on GameObject, on play.

Any clues, what might be the case, here, are very much wellcomed. Otherways, I would have to make the project from scratch and through out of the window a 2 months work!

EDIT 2

I have also tried to move the GameObject that has the Texture Swap Animation script attached, from my initial project, that does not animate on Unity play, to my new testing project as a prefab. Guess what, it animates o.k. on Unity play!

According to these behaviour, I believe there must be a big “BUG” at Unity engine, otherwise why the same prefab, and script plays o.k. in one project and does not plays at the other?

What might be a working arround to this bug? Any thoughts, someone? Please respond.

EDIT 3

Well, here is what I have came up with, after I have tried many things to make the script work again on GameObject texture.

I have added a script that gives user the option to guit app or stay in, with the fuctions “application.quit” and “application.pause”

The coding is as following:

#pragma strict

var count : int = 0;
function Update () {
if (Input.GetKeyDown(KeyCode.Escape)) { 
    Time.timeScale = 0;
    count = 1;
            }
}
function OnApplicationPause()
{
Time.timeScale = 0;
count = 1;
}

function OnGUI()
{
if(count == 1)
    {
       GUI.Box(new Rect(0,0,Screen.width,Screen.height),"Exit");
       GUI.Label(new Rect(Screen.width*1/4,Screen.height*2/6,Screen.width*2/4,Screen.height*1/6), "Are you sure you want to exit the game?");
    if(GUI.Button(Rect(Screen.width/4,Screen.height*3/8,Screen.width/2,Screen.height/8),"Yes"))
          {
         Application.Quit();
          }
          if(GUI.Button(Rect(Screen.width/4,Screen.height*4/8,Screen.width/2,Screen.height/8),"Keep Playing"))
          {
          count = 0;
          Time.timeScale = 1;
          }
    }
}

So far, I had not enabled this “exit” script. Upon enable it in Inspector and hit play in Unity, I also got the “Texture Swap Animator” script running o.k. This is happening after I hit “keep playing” as an option on the “exit” script.

I believe, the “Texture Swap Animator” script is getting somehow in a “pause” state, because a conflict and therefore is activated once the “keep playing” button is clicked in the “exit” script, which is canceling any “pause” state in app.
Does this outcome, ring a bell to someone, to make the “Texture Swap Animator” work again flawlessly?

Waiting for your answers.

EDIT 4

As @ThermalFusion and @Dante suggested, the “Time.timeScale” variable is a trigger to whether the “TextureSwapAnimator.js” script runs on a GameObject or not. Strange thing is that this script used to run before I have added the coding of “Time.timeScale” in my other js script that I do a call to run the “TextureSwapAnimator.js” script.
I have mocked around the “1” and “0” switches in the “Time.timeScale” variable, and I have texture animation as functionality, but I have lost the functionality of the “Exit” script!

Here is the “Exit” script modifications I’ve made:

#pragma strict

var count : int = 1;                                          // changed from 0 to 1
function Update () {
if (Input.GetKeyDown(KeyCode.Escape)) { 
    Time.timeScale = 1;                                  //changed from 0 to 1
    count = 0;                                                 //changed from 1 to 0
            }
}
function OnApplicationPause()
{
Time.timeScale = 0;
count = 0;                                                   //changed from 1 to 0
}

function OnGUI()
{
if(count == 0) // changed from 1 to 0
    {
       GUI.Box(new Rect(0,0,Screen.width,Screen.height),"Exit");
       GUI.Label(new  Rect(Screen.width*1/4,Screen.height*2/6,Screen.width*2/4,Screen.height*1/6),  "Are you sure you want to exit the game?");
    if(GUI.Button(Rect(Screen.width/4,Screen.height*3/8,Screen.width/2,Screen.height/8),"Yes"))
          {
         Application.Quit();
          }
          if(GUI.Button(Rect(Screen.width/4,Screen.height*4/8,Screen.width/2,Screen.height/8),"Keep Playing"))
          {
          count = 1;                                     //changed from 0 to 1
          Time.timeScale = 1;
          }
    }
}

Now after all these editing, what do you thing is the problem with this coding? A bug in Unity3d, a conflict in scripting or what else?
Waiting for your thoughts and answers. Thank you all for your time and efford.

Likely you are using a material with a shader that doesn’t have/use the _MainTexture property.
Or maybe missing renderer with materials all together. Otherwise the code would work.

Hi @ThermalFusion. I am a newbie in Unity, maybe I have done something that changed those properties. How can I make it work out as it should be? Where should I found those _MainTexture in Inspector? Thanks in advance.

Those properties are found in the shaders. What material are you using? Does it work if you use a material using the Diffuse shader?

Hi again @ThermalFusion. I am using the base (RGB) shader of Mobile/Diffuse. I have tried almost every diffuse shader, but still can get it to work.
Why was this script used to work and now it doesn’ t? It is very strange, cause I can’t get any texture swapping script to work. Any clues?

Post shots of your setup. Need more info

Hello again @ThermalFusion. I’m posting a screen shot of Unity’s Inspector, showing the properties of the GameObject, used with the texture swap script.
Hope it might be of anyhelp to you, so we can figure out what is wrong and the script does not run as it should. I should remind you, that when I had started the development of my app in Unity, that script worked ok in every scene, and on any GameObject.

EDIT 1.
Strange thing is that on starting a new project the script works o.k., on every GameObject. Furthermore, I’ve tried to copy the working attributes of the new project GameObject to my previous project settings, but it didn’t work out. It is a pity to start my project from scratch to make this script working again as I’ve been working on this for about 2 months!
Is there a bug in Unity3d or something else being broken in its installation and it is not working as before?

The mesh renderer needs a material. Add a material and it is going to work.

If you hit play with that setup, you are getting error messages. it would have been useful if you had posted that information.

Hello @Dantus. Thank you for your reply to my question. Apologies for double posting. Didn’t know if it was a scripting issue or a Unity bug. I still haven’t figured it out.

You recomented to add a material to the mesh renderer, for the script to work. Well, I had already a material applied, but I got no functionality of the script. I have reseted the mesh materials to defauld, still got no script to work in my initial project.

In the new project everything is working o.k. in Unity play. Furthermore, I got this error messages in console “NullReferenceException: Object reference not set to an instance of an object”, but this has nothing to do with the Texture Swap Animator script, cause it is a NyARtoolkit bug I suppose.

I’m posting two screenshots from Unity Inspector. One (named “A”) is from my initial project, where the script used to run o.k., and now it does not runs at all. The second (named “B”) is from a new project, that the script runs just fine!.

Any clues, what might be the culprit here? I suppose it might be a Unity bug or something, and what can it be as a solution, to avoid starting project from scratch?

Did you try to change the layer to “2D GUI”?

Yes @Dantus. The initial project has a 2D GUI layer. The new project, that it is used to test the script functionality, has only the default layer.
I have tested the layers and this is not the issue. I have moved the objects between layers, I have created new camera that sees only the gameobject with the script attached, I get zero functionality from the script in my initial project. No matter what I try in my initial project I get no responce from script in Unity play. I repeat, same settings in new project and everything in script its o.k. What could be broken in my initial Unity project?

var frames : Texture2D[];
var framesPerSecond = 10.0;
 
function Update () {
	var index : int = Time.time * framesPerSecond;
	index = index % frames.Length;
	renderer.material.mainTexture = frames[index];
	Debug.Log ("Update was executed. " + Time.realtimeSinceStartup);
}

Try to add the Debug.Log to the script to see, whether it gets executed.

Are you pausing time? That would also stop the animation.

Hello @Dantus. I have added the Debug.Log line at script as you suggested. I get the following message at console:

“Update was executed.14.39214
UnityEngine.Debug:Log(Object)
TextureSwapAnimator:Update() (at Assets/Standard Assets/Scripts/General Scripts/TextureSwapAnimator.js:8)”

What does this means? Is the script executed, or not? If so, why cannot see the texture animating on GameObject?

Hi again, @ThermalFusion. No I’m not pausing time. I just hit “play” in Unity, that all.

Do you only see this message once? This message is printed each time when the texture is swapped.
Again, do you have other error messages in the console? Any error message is relevant!

Hi @Dantus, I get this message uncountable times, as it is an update function I supposed, it is o.k. to be reported so, in console.

I also get the following error, that has nothing in my opinion to do with the Texture Swap script :
“NullReferenceException: Object reference not set to an instance of an object”. This is a error generated from the NyARtoolkit, but the project used to run o.k, both on player and on testing device.

Change the debug line to

Debug.Log ("Update was executed. Index: " + index + "; " + Time.realtimeSinceStartup);

Like that you will see the index of the currently shown texture.

@Dantus, I changed the debug line as you suggested, hit “play” and I got the following message in console:

“Update was executed. Index: 0; 40.81854 (← this number constantly changes)
UnityEngine.Debug:Log(Object)
TextureSwapAnimator:Update() (at Assets/Standard Assets/Scripts/General Scripts/TextureSwapAnimator.js:9)”

How this report interpretes? I believe the “0” means nothing is rendered? or what?

0 means always the first frame is shown. Please tell me which value you get, when you replace the Debug.Log with this:

Debug.Log (Time.time);