I was playing with idea to extend the game functionality by adding multi-player support early on. There is very nice tutorial Unite 2014 – New Unity Networking in 5.x., but I was missing one detail. How was Sean Riley able to instantiate game object from prefab. I always ended with some kind of exception or failure.
After several attempts to determine the root cause of my problem I stumbled upon this video “28.Unity Prefabs, Instantiate – Unity C# Scripting Tutorial Beginners” – from Charger Games. I was watching very closely and replayed the sequence several times to find the trick.
Here is whole process in slow motion.
1. Create Prefab from some game object. In my case I will focus on instantiating a pear.
2. Create Empty Game Object and add component Script in C#.
3. Open the script in editor.
4. Define public GameObject, save the code.
5. Go back to Unity Editor and watch the magic. :-)
6. Unity parsed the code and updated fields in Inspector panel. Drag you prefab and drop it into the new slot.
7. Go back to the code and instantiate it.
That’s all. It reminds me of Xcode when you had to drag some stuff into sockets to bind it with code.
Here you can test updated version of Siriel.
During publishing this post I discovered issue with Unity that some assets are not properly loaded when switching between build for Desktop and WebGL. Read more at Unity forum about workaround.