A Unity ID allows you to buy and/or subscribe to Unity products and services, shop in the Asset Store and participate
in the Unity community.
Discussion in 'Scripting' started by kirisakichioge, Jul 7, 2021.
Is the file you want to load inside your "Resources" folder?
when i write the same code in start function ,is working ,What bothers me is why the following code is not executed
For one thing, never use Resources.Load() as T
Always use the Resources.Load<T>() form, in this case with a T of GameObject.
The reason: using Resources.Load("Foo") as GameObject might load a material or something else named "Foo" that is not a GameObject. Then when you cast-as to GameObject it will come out mysteriously null and cause errors.
More insidiously, if you have Foo.png and Foo.prefab, it is a 50/50 chance of what you'll get, and it may vary from install to install. Don't tempt fate.
If you use Resources.Load<GameObject>( "Foo") (or also Resources.Load<Texture2D>( "Foo")) you will get the correct object every time, assuming you meet the directory naming requirements (see docs).
For two things, make a fresh script, test the load function without all the network and callback stuff. Get that working first. Start with the Resources.Load<T>() script documentation to ensure you are meeting 100% of the requirements. There are several very specific requirements.
Resources.Load() as T
Resources.Load("Foo") as GameObject
thanks,the code in update function is executed,but openform function did not work correctly,maybe is async problem?my english is not well,i don't know if i made it clear (T⌓T)
If that is not called from the main thread, it probably won't work. Marshal it to the main thread.
thanks,I'll give it a try
I don't really spend much time looking at code in a PNG file... that's why if you post a code snippet, ALWAYS USE CODE TAGS:
How to use code tags: https://forum.unity.com/threads/using-code-tags-properly.143875/
Looking above, the traditional way you handle things line "OnConnect()" is that you do almost nothing. You just set a boolean to true and store down any data you might get back, nothing else.
Then in your Update() loop it goes "Hey, I see the boolean is true!" and proceeds.