Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How do I Spawn a Network Object with scriptable object data attached to it?

Discussion in 'Netcode for GameObjects' started by CptMarvel21, May 9, 2022.

  1. CptMarvel21

    CptMarvel21

    Joined:
    Sep 18, 2021
    Posts:
    11
    I've been trying to figure out how to spawn an object to the network with its scriptable object data. Only the host sees the scriptable object data but none of the clients do. IS it not possible to spawn an object with a scriptable object attached to it?
     
  2. luke-unity

    luke-unity

    Unity Technologies

    Joined:
    Sep 30, 2020
    Posts:
    306
    Out of the box this is not possible. Here is how I would approach this. Give each of your scriptable object an index by storing it in an array on a manager. Use a NetworkVariable<int> to synchronize the index of the data and on the other side you can use the OnValueChanged callback of the network variable and read the int and find the corresponding data for it.
     
  3. gamedevjake

    gamedevjake

    Joined:
    Aug 16, 2022
    Posts:
    1
    Thanks for this suggestion! Is there an example you could direct us to? I'm not sure how to store Scriptable Objects into an array, in particular, since my SOs are created as .asset files and not C# objects.