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
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 $$anonymous$$ · 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.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Detacting Collision Over Photon Network 0 Answers

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

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] 1 Answer

Pushed back when applying NetworkTransform 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