Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by Carbongrip · Apr 27, 2014 at 04:30 AM · c#playernetworkdestroylevel

Level Joining Issue

Hello all I was wondering if anyone has any ideas why I have with players and the map when they join the LAN game. So if the host starts the game and changes the map by clicking on some blocks and destroying them (like a cube game) then someone joins the game (client) they don't see the changes made to the map. However all future changes once they join are seen just fine. I even tested where server starts the game and does nothing then the client joins before any changes are made there is a perfect sync. So why does this happen? Does anyone got any ideas to this? I would really appreciate everyones help and advice. Here is the network code with what makes the cube map.

 using UnityEngine;
 using System.Collections;
 
 public class NetworkManager : MonoBehaviour
 {
     public GameObject playerPrefab;
     public GameObject snow;
     public Transform spawnObject;
 
     private bool done = false;
 
     void OnGUI()
     {
         if(!Network.isClient && !Network.isServer)
         {
              if (GUI.Button(new Rect(Screen.width/2,Screen.height/2,100,20),"Start Server"))
              {
                 startServer();
             }
 
             if (GUI.Button(new Rect(Screen.width/2,Screen.height/2 + 60,100,20),"Connect"))
             {
                 Network.Connect("###.###.#.#", 25000);
             }
         }
     }
 
     void Awake()
     {
         Network.minimumAllocatableViewIDs = 20000;
     }
     
     void Update()
     {
     
     }
 
     void startServer()
     {
         Network.InitializeServer(32,25000, !Network.HavePublicAddress());
         if(Network.isServer)
         {
             for (int x = 0; x < 28; x++)
             {
                 for (int y = 0; y > -2; y--)
                 {
                     for(int z = 0; z < 28; z++)
                     {
                         GameObject ChuckSpike = Network.Instantiate(snow, new Vector3(x, y, z), Quaternion.identity,0) as GameObject;
                         ChuckSpike.transform.tag = "chunk0";
                     }
                 }
             }
         }
     }
 
     void OnServerInitialized()
     {
         Debug.Log("server initialized");
         spawnPlayer();
         
     }
 
     void OnConnectedToServer()
     {
         spawnPlayer();
     }
 
     void spawnPlayer()
     {
         Network.Instantiate(playerPrefab, spawnObject.position, Quaternion.identity, 0);
     }
 }
 
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 HuskyPanda213 · Apr 27, 2014 at 04:57 AM 0
Share

Is it loading a level, when the game starts, or client joins. Try adding a script to the blocks that looks like this:

 using UnityEngine;
 using System.Collections;
  
 public class Network$$anonymous$$anager : $$anonymous$$onoBehaviour
 {
 
 void Awake()
 {
 DontDestroyOnLoad(gameObject);
 }
 
 void OnDisconnectedFromServer()
 {
 Object.Destroy(gameObject);
 }
 
 }

If that script works what is happening is, when a client joins something (presumably level loading) is causing the changes to be erased.

avatar image Carbongrip · Apr 27, 2014 at 05:20 AM 0
Share

hmmm... that didn't seem to work but I see what you were thinking.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Carbongrip · May 04, 2014 at 09:36 PM

turns out when destroying a object you have to do this...

 Network.RemoveRPCs(hit.transform.networkView.viewID);
 Network.Destroy(hit.transform.root.gameObject);

if you don't then it only deletes for the users on and not future users. How ever for creating objects you just need the Network.Instantiate. Unity3d really needs to make this more clear and at least state this in the documentation for Network.Destroy.

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

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

20 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

Related Questions

Multiple Cars not working 1 Answer

Networked Game Issues - Camera does not follow script 1 Answer

Distribute terrain in zones 3 Answers

Error destroying player over network 1 Answer

How can i acess the local Player from Script 1 Answer


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