Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
This question was closed May 22, 2016 at 06:44 PM by orenji for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by orenji · May 19, 2016 at 03:05 PM · networkingmultiplayerunity5synchronizationprefab-instance

[uNET] Instantiated gameobjects not syncing for new clients

Hello!

 using UnityEngine;
 using UnityEngine.Networking;
 using System.Collections;
 
 public class Weapons : NetworkBehaviour {
 
     public bool rif = true;
     public GameObject rifleprefab;
     private GameObject rifl;
     public GameObject rightHand;
     [SyncVar]
     public bool haswep = false;
     [SyncVar]
     public GameObject weapon;
     [SyncVar (hook = "OnWeapon")] public NetworkIdentity hasRifle;
 
     // Use this for initialization
     void Start () {
         if(isLocalPlayer)
         {
             ClientScene.RegisterPrefab(rifleprefab);
             ClientSpawn();
         }
     }
 
     [Client]
     void ClientSpawn()
     {
         if (isLocalPlayer)
         {
             if (!haswep)
             {
                 CmdSpawnRifle(transform.position, transform.rotation, rightHand);
                 haswep = true;
             }
         }
     }
 
     void OnWeapon(NetworkIdentity hasweapon)
     {
         weapon.transform.SetParent(rightHand.transform);
         weapon.transform.localPosition = new Vector3(0.0896f, -0.0204f, 0.0275f);
         weapon.transform.localRotation = Quaternion.Euler(-29.4f, 111.3f, 86.617f);
 
     }
 
     [Command]
     public void CmdSpawnRifle(Vector3 p, Quaternion r, GameObject g)
     {
 
         GameObject rifle = Instantiate(rifleprefab, rightHand.transform.position, transform.rotation) as GameObject;
         NetworkServer.SpawnWithClientAuthority(rifle, base.connectionToClient);
         weapon = rifle;
         hasRifle = gameObject.GetComponent<NetworkIdentity>();
     }
 
 
     public void Fire()
     {
       
     }
 }

With this code, when a new player connects, it actually spawns the gameobject for himself and for other players, but the gameobject isn't parented (so it just floats there). Whereas, for the already connected clients, it works perfectly. If the other clients respawns, it will work.

I don't know at all how I should correct that, there might be something wrong in my code. Any idea how to fix it please?

alt text

unity2016-05-19-16-47-32.png (263.7 kB)
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Scribe · May 19, 2016 at 07:37 PM 0
Share

Perhaps it need rightHand to be sync'd as well?

avatar image orenji · May 19, 2016 at 07:46 PM 0
Share

Surely but how should I sync that? With a SyncVar? But I will need a Cmd no? Edit: And thank you btw

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by orenji · May 22, 2016 at 06:44 PM

http://stackoverflow.com/questions/31359668/unity-5-1-networking-spawn-an-object-as-a-child-for-the-host-and-all-clients

The last code helped me, thanks everybody!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Follow this Question

Answers Answers and Comments

94 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

UNet - sync child transform scale 1 Answer

Unet Syncing Flashlights 2 Answers

how to split player objects over network? 0 Answers

Unity 5.1 networking 0 Answers

Problem with using Unity Spawnsystem (Unet / Multiplayer) 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges