• 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
1
Question by paternostrox · Jan 26, 2016 at 12:25 PM · unity 5multiplayernetworkcrafting

UNET: Spawning AND moving objects!

So, i'm trying to achieve an online multiplayer building system, where prefabs have to be spawned and placed in the desired position by the players.

My issue is: I can spawn, move and place the objects with no issue on the host (and it appears to all clients), but on the client I can spawn (in the correct place initially), but not move them afterwards, it gets stuck on the initial position. The object itself has no scripts. The script I have handles the spawns/placement of the objects, is attached to the player and is the one bellow:

I've already searched a lot on this matter, and didn't find any example that suits my case (most cases are simple spawns, like bullets or so), my client needs to edit the position/rotation of the prefab after it is spawned, even with 'SpawnWithClientAuthority' the client isn't able to do it (only the host).

Also I'm almost sure that everything is set correctly on the editor, prefab is registered as spawnable prefab, objects have network identity/transform and are set to local player authority.

  using UnityEngine;
  using System.Collections;
  using UnityEngine.Networking;
  
  public class Crafting : NetworkBehaviour {
  
      public GameObject obj;
      private GameObject rf;
      private Vector3 objpos, objtrot;
      private bool building;
      void Update () {
          if (!isLocalPlayer) return;
          if (Input.GetKeyDown(KeyCode.Q) && !building)
          {
              CmdSpawn();
              rf.transform.Rotate(-90, 0, 0);
              building = true;
          }
  
          if (building)
          {
              objpos = new Vector3(Mathf.Round((transform.position.x + (7 * transform.right.x)) / 6) * 6, -19.95f, Mathf.Round((transform.position.z + (7 * transform.right.z)) / 6) * 6);
              rf.transform.position = objpos;
              if (Input.GetKeyDown(KeyCode.R))
              {
                  rf.transform.Rotate(0, 0, 90);
              }
              if (Input.GetKey(KeyCode.E))
              {
                  building = false;
              }
          }
      }
  
      [Command]
      void CmdSpawn()
      {
          rf = (GameObject)Instantiate(obj, new Vector3(Mathf.Round((transform.position.x + (7 * transform.right.x)) / 6) * 6, -19.95f, Mathf.Round((transform.position.z + (7 * transform.right.z)) / 6) * 6), Quaternion.identity);
          NetworkServer.SpawnWithClientAuthority(rf, connectionToClient);
      }
  }
Comment
Add comment · Show 1
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 toomasio · Sep 01, 2016 at 08:35 AM 0
Share

Did you ever find a solution to this? I have the exact same problem.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by wobes · Jun 29, 2016 at 05:43 PM

Put the Network Transform on building Object

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

im making a multiplayer game, and it has buttons that allow you to craft different blocks, how do I set a reference to the player game object so each player can build different amounts of blocks? 0 Answers

How to get reference of the Local Game Player when a Game Scene is Loaded from a Lobby Scene [Multiplayer] 0 Answers

Pushed back when applying NetworkTransform 1 Answer

Detacting Collision Over Photon Network 0 Answers

Multiplayer Object spawned by client does not show up on host 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges