Instatiate() confusion

Hi there experts. Please enjoy a wry smile at my newbie confusion. :smile:

I’m doing some early tests on Unity3.0 iOS with C#. I have managed to create a builtin Array of Objects and populate it with Objects spawned from a prefab in the assets folder at runtime using the return results from Instantiate() in a for loop on Start(). The prefabs spawn correctly into the game world with random positions.

I’d now like to manipulate those Objects using Rotate() Translate() within the Update() etc…

myArray[0].transform.Translate(1.0f,0.0f,0.0f);

Q1. The Objects referenced by the array don’t seem to allow for this. Do I need to cast differently or use getCompenent or something similar?

Q2. Why does Instantiate() return an Object data type, not a GameObject? I thought Instantiate cloned asset prefabs, and a prefab was a GameObject.

Many thanks for any advice!

Richard

what is your array made out of objects or GameObjects?
You need to explicitly cast the return from instantiate to GameObject.
Otherwise your translate code should work fine.

you may want to check this fresh thread:
http://forum.unity3d.com/threads/66673-Instantiate-Error-Must-be-missing-something-simple…

Hi ivkoni,

I was originally creating an array of Objects as Instantiate returned data type Object.

I have just tried creating an array of GameObjects, and explicitly casting the return result of Instantiate() to type (GameObject).

I can now access the tranform functions. Hooray!

Thanks for your insanely fast response.

Richard