Search code examples
unity-game-engineaugmented-realityvuforiaunity-networking

Instantiate new "players" in a sub folder in Hierarchy view | Unity networking with Vuforia


I am using Vuforia for creating a basic multiplayer AR project. My immediate requirement is to display multiple players in the same scene - each player is to be controlled by a separate device connected to the same network.

My current Hierarchy view is like this:

Initial Hierarchy view - using Vuforia

According to Vuforia, all assets to be rendered should go under ImageTarget. I have a player prefab which basically contains the UnityChan character along with a small player movement script (tap/ click to move to a point). The network manager is responsible for instantiating player for each device (i.e. "client" or connection) from that prefab.

Network Manager

However the player objects are created in the root folder in Hierarchy view. So they are never visible in the actual AR scene. Here's the hierarchy view during "play" mode (2 devices connected) -Hierarchy view - during play mode; 2 connections

So my question is: how can I instantiate the "players" inside the ImageTarget folder instead, so that they are visible in my AR scene?


Solution

  • You set the parent.

    Something like this

    Transform imageTargetTransform = GameObject.FindObjectOfType<ImageTarget>().transform;
    
    Player player1 = Instantiate<Player>(playerPrefab);
    player1.tranform.parent = imageTargetTransform;
    

    IDK your class names though so youll need to adapt the above for your needs.