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 /
avatar image
0
Question by fet0r · Jan 09, 2018 at 01:00 AM · networkingmultiplayer-networkingspawning problemsclient-serverclients

UNET Different size of spawned object on host and client

Hello If I spawn the object from host, on other Clients is bigger. alt text alt text

Only local player can spawn objects. Console shows the error when client tries to spawn block:

"NullReferenceException: Object reference not set to an instance of an object GameManager.Update () (at Assets/Script/GameManager.cs:87)"

 using UnityEngine;
 using System.Collections;
 using System;
 using UnityEngine.EventSystems;
 using UnityEngine.UI;
 using UnityEngine.Networking;
 
 
 public class Block
 {
 
     public Transform blockTransform;
 }
 
 public struct BlockAction
 {
     public bool delete;
     public Vector3 index;
 }
 
 public class GameManager : NetworkBehaviour
 {
     public static GameManager Instance { set; get; }
 
 
     private float blockSize = 0.25f;
 
 
     public Block[,,] blocks = new Block[100, 100,100];
     public GameObject blockPrefab;
 
     private GameObject foundationObject;
     private Vector3 blockOffset;
     private Vector3 foundationCenter = new Vector3(10f, 0, 10f);
 
     [SyncVar]
     private bool isDeleting;
 
     public Button deleteButton;
     public Sprite[] deleteButtons;
 
     [SyncVar]
     private int blockIndex = 0;
 
 
 
 
     private void Start()
     {
         Instance = this;
         foundationObject = GameObject.Find("Foundation");
         blockOffset = (Vector3.one * 0.5f) / 4;
     }
 
     private void Update()
     {
         if (Input.GetMouseButtonDown(0))
         {
             RaycastHit hit;
             if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 30.0f))
             {
                 
                 if (isDeleting)
                 {
                     if(hit.transform.name != "Foundation")
                     {
                         Vector3 oldCubeIndex = BlockPosition(hit.point - (hit.normal * (blockSize - 0.01f)));
                         NetworkServer.Destroy(blocks[(int)oldCubeIndex.x, (int)oldCubeIndex.y, (int)oldCubeIndex.z].blockTransform.gameObject);
                         blocks[(int)oldCubeIndex.x, (int)oldCubeIndex.y, (int)oldCubeIndex.z] = null;
                     }
                     return;
                 }
 
                 Vector3 index = BlockPosition(hit.point);
 
                 int x = (int)index.x
                     , y = (int)index.y
                     , z = (int)index.z;
 
                 if (blocks[x, y, z] == null)
                 {
                     CmdCreateBlock (index);
                     GameObject go = GameObject.Find ("Block" + (blockIndex - 1));
 
                     blocks[x, y, z] = new Block
                     {
                         blockTransform = go.transform,
                     };
                 }
                 else
                 {
 
                     CmdCreateBlock (index);
                     GameObject go = GameObject.Find ("Block" + (blockIndex - 1));
 
                     Vector3 newIndex = BlockPosition(hit.point + (hit.normal * blockSize));
                     blocks[(int)newIndex.x, (int)newIndex.y, (int)newIndex.z] = new Block
                     {
                         blockTransform = go.transform,
                     };
                     PositionBlock(go.transform, newIndex);
                 }
             }
         }
     }
 
     [Command]
     void CmdCreateBlock(Vector3 index)
     {
         GameObject go = Instantiate(blockPrefab) as GameObject;
         go.name = "Block" + blockIndex.ToString();
         go.transform.position = ((index * blockSize) + blockOffset) + (foundationObject.transform.position - foundationCenter);
         go.transform.localScale = Vector3.one * blockSize;
         blockIndex += 1;
         NetworkServer.Spawn (go);
     }
 
     private Vector3 BlockPosition(Vector3 hit)
     {
         int x = (int)(hit.x / blockSize);
         int y = (int)(hit.y / blockSize);
         int z = (int)(hit.z / blockSize);
 
         return new Vector3(x,y,z);
     }
     public void PositionBlock(Transform t, Vector3 index)
     {
         t.position = ((index * blockSize) + blockOffset) + (foundationObject.transform.position - foundationCenter);
     }
 
     public void ToggleDelete()
     {
         isDeleting = !isDeleting; 
         deleteButton.image.sprite = (!isDeleting) ? deleteButtons[0] : deleteButtons[1];
     }
 }


screen2.jpg (14.5 kB)
screen1.png (188.1 kB)
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by CStampGames · Jan 09, 2018 at 01:21 AM

I'm having a similar issue

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

109 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 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

Only host can spawn objects on server, when the client tries to spawn an object it returns the error, "NetworkServer is not active. Cannot spawn objects without an active server." 1 Answer

Spawning Dynamically created GameObjects on a network 0 Answers

Unet Networking: having two clients in the editor instead of building for standalone? 0 Answers

[UNET] Only spawn certain server objects on local client? 0 Answers

Network command is running on client? 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