Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

is it possible to have GameObject with NetworkIdentity preloaded in scene?

Discussion in 'Multiplayer' started by chetan-rane, Dec 16, 2015.

  1. chetan-rane

    chetan-rane

    Joined:
    Nov 26, 2012
    Posts:
    18
    Hi,

    I want gameobject (with NetworkIdentity) already loaded in scene. By default NetworkIdentity disabled the objects.

    As i want to support offline and online play.
    Is it possible? is there any way to achieve this? or there is any alternative?

    – Chetan
     
    Sisso likes this.
  2. DRRosen3

    DRRosen3

    Joined:
    Jan 30, 2014
    Posts:
    683
    No. Network Identities are "filled out" at the time of Network.Spawn()'ing. They have to be created after the server is up so that their properties can be assigned properly. What you could do, and are probably going to have to do, is have two different scenes. One that's loaded for online play and one that's loaded for offline play. In the offline scene simply remove the Network Identity from the GameObject (as well as any NetworkBehaviours).
     
  3. ObliviousHarmony

    ObliviousHarmony

    Joined:
    Jul 3, 2014
    Posts:
    79
    Hello,

    Yes, you can. By default, after loading a scene, all of the objects are inactive. You can however, change that.

    If you're simply looking to bring them to life, you can make use of this http://docs.unity3d.com/ScriptReference/Networking.ClientScene-spawnableObjects.html to find the disabled objects, and then you can do with them as you please. If you do this (hell, just in general!), it's a wise idea to separate your gameplay components from your NetworkBehaviour components, that way you can pull them out and the game will function as a single-player game.

    The default use case however, is probably to have the client and server capable of existing within the same application. In the case of having a server spawn the assets, you can use this: http://docs.unity3d.com/ScriptReference/Networking.NetworkServer.SpawnObjects.html The idea here would be that your "server" also runs the client gameplay logic, the same as any client, but also runs the server logic.
     
  4. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    Yes. The easiest way to support "offline" play is to run as a host with no clients.