Unexpected Instantiate (clone?) Behaviour

Howdy there, newbie to both Unity and the VRCSDK here so this could be related to either, but hopefully the latter… (if not just delete this post)

I’m experiencing some weird behaviour when using Vrchat Instantiate.

I’m making a script, to instantiate a cube at game start.

This is put on instantiate_caller which is an empty game object in the world.

The script works fine when it looks like this.

i.e. it instantiates 1 cube at the same position of the prefab asset, and then stops.

Now for the issue

I want to now move this clone to another location.

To do so, I get the transform of the clone, and set that to the location I want.

But now when I run it… I get TWO cubes!

One of them is at the same location as before the transform.

And one of them is at the location after the transform.

This is very strange!

I have found a workaround that achieves the same end goal (only works in unity editor, not vrchat itelf) however, by translating the prefab to the location I want first, and then instantiating it.

This produces the expected output of only 1 new cube at the desired location being created.

So my question is why does getting the transform, and then setting it on the output of the Vrchat Instantiate method, cause a second clone to be created, but not if done in the other order? Any enlightenment would be much appreciated.

No urgency to reply, I’m just curious :slight_smile:

(omitted pictures are due to me being a new user and having a limit of 5) (pictures are now added as my rank went up for some reason)

edit: the workaround I mentioned only seems to work within unity, not when playing within vrchat itself (the cube remains in the original position in vrchat)

edit: the duplication occurs slighly differently when running in VRChat, the duplicate appears at 0,0,0 rather than at the prefab’s location (one of them is still correctly moved to the desired location however, and there are still two cubes created).

edit: just added pictures

Current state of instantiating objects is a bit bugged. So a bit expected to see issues like these.

It’s also incomplete, as there is no way to have it instantiate for all players (everything is local at the moment.)

1 Like