Hello! im getting this error, what does it mean? Code (CSharp): GetLocalizedString can only be called from the main thread. Constructors and field initializers will be executed from the loading thread when loading a scene. Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function. It dont tell what script making the error, but its clearly my script for loading scenes with buttons.
The comment in this question might help: http://answers.unity3d.com/questions/995185/applicationloadlevel-argumentexception.html Seems like a strange error, could be many things causing it.
Often you get this when attempting to call a function at the definition stage. If you are doing this, try moving it to Awake instead.
I got this error a couple of times after upgrading my project to Unity 5. Turns out I had trees I made from the tree creator in my scene. Once I removed them, the error went away.
??? No official has commented on this thread. Do you have an official comment somewhere else? Normally the stance from Unity developers is to not change engine versions in late stage development.
Old reply, but I just had this problem. For me its caused by trees. I grabbed everything in the scene, put it under an empty game object, made a prefab from it. Deleted the prefab. Errors gone.
Same here. I've been making as much noise about it as I can for months and months without any reply from anyone at Unity. Is this ever going to be fixed? Code (csharp): ArgumentException: GetLocalizedString can only be called from the main thread. Constructors and field initializers will be executed from the loading thread when loading a scene. Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function. TreeEditor.TreeGroupRoot..cctor () Rethrow as TypeInitializationException: An exception was thrown by the type initializer for TreeEditor.TreeGroupRoot I tried the prefab trick and it worked, but it'd be a lot better if this issue just never came up again.
Actually no, it didn't work. The first time it kind of did (my original terrain was still there though, just unchecked) but the second time (deleting the original terrain) it caused a bunch of other things to break in addition to the original errors showing up again. Something to do with it being a prefab I guess. So... No. The prefab trick does not work.
Just tried it. It worked the first time I hit play, but after that the errors return, so nope, it didn't really work or I'm still missing something. It's a pain because any time I change scenes in play mode it pauses Unity so you can see the errors. When it's running in the Rift I turn off the mouse cursor which makes it a bit tricky to hit the play button.
Just to keep you updated, we have seen the problem and someone reported a very useful incident which we can use to reproduce the issue. We will work on a solution to the problem, in the meantime please try the workaround posted by @FlyAnvil and let us know in the thread of the workaround if it works for you or not as it might help to solve the issue when we know more about the behaviour. You can follow the report and outcome here: http://issuetracker.unity3d.com/iss...-error-messages-when-loading-scene-with-trees
FWIW, i was having the same issue...And this worked.. I deleted the trees from the scene and re-added them (luckily there position was not important).. and after doing that, the error is gone. Also, in case it matters, i went as far as deleting the trees and re adding them (useing the "edit trees" button in the terrain editor). I then repainted the trees on the terrain.
@David Berger The solution suggested by FlyAnvil didn't work for me. I just selected Edit Tree and Apply for each tree in the terrain; I didn't try ev3d's solution of deleting and repainting each tree, as I have too many in the scene to do that all again unless absolutely necessary.
Sorry, I'm missing something. Where are you clicking "edit tree" and "apply?" Are you clicking the tree prefabs in the project or is this something you're doing in the scene hierarchy? I'm using Terrain Composer which adds the trees to the terrain itself, so if this is something that has to be done directly on the trees in the Unity terrain editor, I'm not sure if I can solve the problem this way. If it's just something I can fix by fiddling with the tree prefabs directly, that'd be great because I only have a few of them in my scenes. Wouldn't take long at all to do.
Think I found it. Guess it doesn't matter if I'm using Terrain Composer or not. The trees are there when I click the terrains in the hierarchy. However, when I click a tree and hit "edit trees" and then "edit tree" in the dropdown under that, I am not able to click "apply" on all of the trees. Some of them give the error "tree has already been selected as a prototype" as shown here. No idea what that means.
Ok, I hit "apply" on all the trees that didn't give the error (some of those trees might not be in this scene, I seem to remember only using a few of them). It fixed it, but only for the first time that I pressed play. Once I stopped and ran it a second time, the errors returned. So no, this has the same results as the original fix. Still broken for me.
That's fantastic news David, thank you! I'm using 5.3.2f1 at the moment but I'll try and install 5.4.0b2 later today on a separate machine and post the results here.
I've tried it in Unity 5.4.0b2 and can confirm that this issue is fixed. Thanks for your help, David.
I was getting this error in 5.3 and all I had to do was regenerate my SpeedTree materials. This fixed the errors for every scene.
Hi! Is it possible to have this fix available for previous versions of Unity like 5.1.4? Thanks in advance!
@F-R That's not possible as we do not update below 5.3.x at this point anymore. You can read about it here. Keep in mind that this is already a couple of months old and we are on 5.3 now and do not support 5.2 either
Ok so I'll stay with my dirty fixes and workarounds. I wish that one day Unity take some time to make an optimization/cleaning only release with a long term support. Like an island of reliability in this ocean on chaos.
Don't fret F-R... these are a bunch of hard working people that provide an amazing product for FREE to indie devs like us. Everything is a constant sea of change in the world of technology and programming. I've been working on a project in my very limited spare time for the past year. Here's how I avoid drowning in the chaos: 1.) Always back-up your project when you reach major milestones. Always back-up before upgrading. 2.) Don't upgrade your project with every single Unity release. Wait for the dust to settle, do some research and download the version that seems to be the most stable. 3.) ALWAYS read the update release notes. Sometimes most of the updates won't even be needed for your current project and you can wait to update. 4.) Make sure any third party assets are up-to-date and compatible with the version you install as well. Third party assets can be the source of the problem just as often as the Unity engine. Hope that helps.
Can we know more or less when the beta will become a stable release? I am asking because having the exact same problem and I don t have Unity Pro. Using 5.3.3
Getting the same error in 5.4.0b13 EnsureRunningOnMainThread can only be called from the main thread. Constructors and field initializers will be executed from the loading thread when loading a scene. Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function. When using this client socket code, which works fine in Unity 4. Code (CSharp): using UnityEngine; using System.Collections; using System; using System.Net; using System.Net.Sockets; using System.Text; public class AsynchClient : MonoBehaviour { private Socket _clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); private byte[] _recieveBuffer = new byte[8142]; //public UITextList textList; void Awake() { SetupServer(); } private void SetupServer() { string host = "127.0.0.1"; int port = 8888; IPHostEntry hostEntry = null; hostEntry = Dns.GetHostEntry(host); foreach (IPAddress address in hostEntry.AddressList) { IPEndPoint ipe = new IPEndPoint(address, port); try { _clientSocket.Connect(ipe); } catch (SocketException ex) { Debug.Log(ex.Message); } if (_clientSocket.Connected) { _clientSocket.BeginReceive(_recieveBuffer, 0, _recieveBuffer.Length, SocketFlags.None, new AsyncCallback(ReceiveCallback), null); break; } else { continue; } } } private void ReceiveCallback(IAsyncResult AR) { //Check how much bytes are recieved and call EndRecieve to finalize handshake int recieved = _clientSocket.EndReceive(AR); if (recieved <= 0) return; //Copy the recieved data into new buffer , to avoid null bytes byte[] recData = new byte[recieved]; Buffer.BlockCopy(_recieveBuffer, 0, recData, 0, recieved); //Process data here the way you want , all your bytes will be stored in recData Debug.Log(Encoding.ASCII.GetString(_recieveBuffer, 0, _recieveBuffer.Length)); //Start receiving again _clientSocket.BeginReceive(_recieveBuffer, 0, _recieveBuffer.Length, SocketFlags.None, new AsyncCallback(ReceiveCallback), null); }
Thanks but's it was not that. The above is the working code from Unity4. There was a difference in the Unity 5 version that had the problem, in that was trying to write to a textlist instead of the debug.log statement at line 66. ReceiveCallback is called in a different thread (by Mono) and it is not allowed to use any Unity functionality from a different thread. Changing it so that the textlist was populated from the main thread solved it.
It's been fixed. Not sure which version exactly but I'm on 5.3.5p2 and it's not longer an issue here.
You can create own tree in GameObject the Prefabs will generate in Project in this remove component tree the error will gone