Instantiate without declaration of instance

The first C# example in documentation Unity - Scripting API: Object.Instantiate have the line:

Instantiate(prefab, new Vector3(i * 2.0F, 0, 0), Quaternion.identity) as Transform;

As we can see, there is no declaration like:

Transform Blabla = Instantiate(prefab, new Vector3(i * 2.0F, 0, 0), Quaternion.identity) as Transform;

But this example from documentation just do not work.
“Only assignment, call, increment, decrement, and new object expressions can be used as a statement”.

But I don’t need this variable, so I declarate it and my console spammed by:
“The variable `Blabla’ is assigned but its value is never used”

Of course this is not a problem. But it just interested that example from documentation didn’t work.

remove the ‘as Transform’ part in the first code you posted.

when you say:

blah as SomeType;

this is expecting to be used somewhere… it’s an incomplete statement.

It’d be like saying:

b == a;
a + b;
blargh is SomeType

these are all incomplete statements.

so

//incomplete statement
Instantiate(prefab, new Vector3(i * 2.0F, 0, 0), Quaternion.identity) as Transform;

//complete statement
var trans = Instantiate(prefab, new Vector3(i * 2.0F, 0, 0), Quaternion.identity) as Transform;

//complete statement
Instantiate(prefab, new Vector3(i * 2.0F, 0, 0), Quaternion.identity);

not sure why the example C# code says as Transform. Probably some auto-code creation tool converted unityscript to C# and put that stuff in there.

Oh, so simple mistake, I should have know.
Thanks you for wide answer. :slight_smile: