Game not running after start button is pressed - unity3d

There are no compile errors or warnings. My game just starts paused. I can look around but everything is frozen. I even tried to call Time.timeScale = 1; from various start functions. "Error on Pause" is turned off.
Restarting Unity has no effect.
Why is this happening?
HINT:
I figured out that calling Time.timeScale = 1; was not working because the gameObject where the script was attached to, was not set to active.

Check your Time Manager. Sometimes it gets randomly corrupted and the scale drops to Zero.
Time Manager (menu: Edit > Project Settings > Time)

Have you tried to force unpause in script?
EditorApplication.isPlaying = true;
Game can start paused also because of some unknown problems with assests so you can try to reimport them. If it doesn't help your next move should be to reinstall unity.
Also make sure you don't do some very time consuming operations on Awake() and Start().

If anyone else has this error and the described solutions have not helped, check that the Editors Pause on Error option is not checked. If you go the console window you will see that tab option highlighted at the top of the window if it is on, unticking that will allow the game to play if it is starting paused because of an error. This option being turned on would likely be your issue if the issue replicates across different projects.

Related

System.Speech.Recognizer not working in background Unity

I am trying to build a voice assistant and so far i have succeeded very well, the only problem is when i launch the assistant it works flawlessly, untill i alt tab out of the window, or just simply switch to another software. The speech.recognizer (its a dictation recognizer) stops working and as far as i see can' t run in the background even though my project is set to work in the background. Everything else works again after manually restarting the dictation recognizer after being in the foreground again by OnMouseClick(). (That' s what i do atleast as OnLostFocus() seems not to work for me)
Anyone that has an idea on why it stops and how to fix it?
Thanks!
Tried restarting in the background by OnLostFocus() but didn' t work
You need to enable run in background option in the player settings

Lag when exporting functionality into a block in Scratch

I'm new to scratch.
I have this code within a sprite, which works as expected without noticeable lags:
But, when I "export" the flickering into the 'flicker' block, it has a very nasty lag:
I created a special sprite in order to easily "feel" the lag, with this code:
This ball smoothly moves, until (every 5 seconds) there is the flickering effect and it stops for 1 second or so.
Can anyone give me a clue why it happens, and how to prevent it?
The project page is here.
Any assistance would be appreciated.
Let me start by pointing out that the problem does not occur when I launch your project.
I tried it in 5 different web browsers on 3 different devices with 2 different operating systems, and every time, the ball just kept moving.
However, I can make such an issue happen by enabling 'Run without screen refresh' in the 'flicker' block, as follows:
Right-click on the red 'define flicker' block.
From the context menu, select 'Edit'.
In the 'make a block' dialog, turn on checkbox 'Run without screen refresh', then click OK.
I suspect 'Run without screen refresh' claims all processing power, effectively blocking any other (concurrent) scripts.
My guess is, you already fixed the problem yourself by turning off 'Run without screen refresh'.
In general, 'Run without screen refresh' is a great way to reduce lag in scripts where speed is essential. But never use it in a script with 'wait' or 'forever' blocks, or it will cause lag.

Why might a Unity button stop working when X position is not 0?

I'm pretty new to Unity. I have a button that works perfectly in the editor. When I build it and run on Windows or Mac, the button stops working. Other buttons on the same canvas work fine.
If I recreate the button from scratch and then build after each setting, it seems that it stops working when move it - if the X position is 0 it works, otherwise it will not. It still works in the editor at runtime, but when I build it, it stops working.
I'm not sure where to look to see what is happening. Any ideas?
That doesn't seem right. Can you confirm that the Raycast Target is checked on your Button component? It might be that it is off and another object in the scene is preventing you from clicking on it.

Detect gameobject removal from user action

I'm working on a system that automatically generate and release scriptable object that represent uniqueness for gameobject with a given component attach.
The generation process seems to be working really fine, but I'm facing problem when I want to release the scriptable object.
The given script is tagged "ExecuteInEditMode" and is implementating OnDestroy method to advertise a manager that his scriptable object should be deleted.
The problem is that OnDestroy is called in 4 situation from what i can tell :
Click on play
Switching scene
Manual removal (the only one I want to work with)
On editor shutdown
I've been able to avoid the 2 first on with this :
if (Application.isPlaying == false && Math.Abs(Time.timeSinceLevelLoad) > 0.00001f)
But I don't find any good solution for "On editor shutdown" I've seen that EditorApplication.quitting can be use for that case, but documentation warn that this event is not called when unity crash or is forced to quit, and I don't want to lose all my scriptable object if the editor crash.
I'm looking for a robust solution to avoid this problem if someone can help me please.
Thanks, have a nice day
Just handle the application quitting event.
this event is not called when unity crash or is forced to quit, and I don't want to lose all my scriptable object if the editor crash.
When unity crashes, so will your program, so it won't work any ways. Just make sure that under normal operating procedure (so a normal shutdown) you save your modifications.
In Unity3D if you edit your scene and you don't save, if the editor crashes you lose all your changes. The same will happen for what you're building here. In order to mitigate this risk (since prevention is reasonably difficult if not impossible) you can opt to save every minute, always save each change to a temporary location, or save for example every play.
For example i added a script to my project that autosaves the scene(s) whenever i press play, so when editing the scene i press play now and then to test, and it all gets autosaved.

Unity3d editor: how to prevent changes from being undone upon exiting play mode?

Apparently this is some beginner's question (and that I am) but it's driving me crazy and I couldn't find any mention:
I Occasionally forget to exit Play mode and go on building my UI making objects and changes, only to realize that I'm still in Play Mode and as soon as I unpress the play button, these will be purged! I suppose the Unity Editor has its reasons for allowing editing of Scripts/Scenes while in Play Mode (would be happy to hear some examples-maybe testing scenes?) but my main question here is:
Is there some way for me to prevent this behavior? Or at least some trick that you use to prevent me from making changes while in play mode? (Other than becoming paranoid about it and checking constantly...)
Thank you
PS. sigh time to head back to Unity and rebuild that UI that I lost...
Other Unity coders have had this problem before me and they came up with a neat solution.
Setting the UI to a different colour while in playmode "Playmode tint".
You can read the details here (originally posted 2009 but I have checked it still works in latest Unity 5.3):
http://answers.unity3d.com/questions/9159/best-strategies-for-not-accidently-editing-whilst.html
There is no settings to prevent changing things during play mode but there are ways to reduce the chances of losing changes during play mode.
1.Edit->Preferences... -> Colors. Now, on the right change Playmode Tint to red. That will remind you you are making changes in play mode.
2.Click on the gear icon of each component you change during play then click Copy Component. When are done with playmode, select the component you want to keep its changes. Click the gear icon again and this time, Click Paste Component Values.
3.Write an Editor Plugin that will do that for you. This is hard but possible.
Use event to find out when entering playmode. Store all GameObject public important variables such as transform/rigidbody properties in a list.
Wait for the stop event to fire then ask your self which GameObjects to overwrite settings to. Then overwrite the properties of the selected GameObjects That's it.
Usefull APIs for this:
EditorApplication.isPlaying
EditorApplication.isPaused
EditorApplication.isPlayingOrWillChangePlaymode
EditorApplication.playmodeStateChanged += callBackFunc;
EditorApplication.HierarchyWindowItemCallback
EditorApplication.ProjectWindowItemCallback
Note: According to Unity roadmap, a feature that enables you to save playtime changes is in construction and will be released soon but the above seems to be the only way at this time.
You can select objects you want to keep while in play mode, copy them with Ctrl + C, and then just paste them back in with Ctrl + V after returning to edit mode. Then you can eithr delete the originals from the scene or copy values from individual components like #Programmer suggested.