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 /
avatar image
0
Question by N7D · Jul 23, 2018 at 06:33 AM · unity 5networkingspawnproceduralsynchronization

unet synchroinze simple procedurally created map on clients

So, I need to create procedural map composed from different chunks, as you can see on screenshot they are platform chunks, and column chunks. I encountered dozens of problems.

My first idea was to create new gameobject in code to parent all column chunks and than parent it to selected platform, the problem is parenting is not transfered to clients. I also have no idea how to register procedurally generated on server object on client, I guess this is impossible, because you can only pass simple stuff like IDs and seeds etc.


So I tried to do all of this just with spawn for testing, to forget about parenting, regestration... And I encountered one more problem: NetworkServer.Spawn doesn't send localscale

This is how my current code works:

Gameobject with script LevelBuilder, which is NetworkBehaviour calls CmdGenerateLevel in Start.

     [Command]
     public void CmdGenerateLevel(int size, int angle)
     {
         _angle = angle;
         _size = size;
 
         for (var i = 0; i <= size; i++)
         {
             _platformLayers.Add(new List<GameObject>());
         }
 
         var initialPlatform = Instantiate(PlatformPrefab);
         NetworkServer.Spawn(initialPlatform);
 
 
         _platformLayers[0].Add(initialPlatform);
 
         _offsetY = initialPlatform.transform.position.y;
 
         GeneratePlatformsRecursive(initialPlatform, 0);
 
         SpawnColumnsOnRandomPlatforms(10);
 
         StartCoroutine(DestroyOverTime());
 }


Constraints are:

  • All of the chunks can be damaged or destroyed during the game;

  • Clients can join during the game and must get the current state.

Question: Can you suggest me a good way of synchronizing this chunks between server and clients? And what is a good way to SetParent of object on both server and client?

It sounds like something easy, but I'm still newbie in networking, so even after 8 hours of trying to find a solution I still haven't managed to do it right.


Screenshot with how the game looks like on server and how I also want it to be seen on client.

https://prnt.sc/k9hzdq

Screenshot



Also code example for generation of this random state

     private void BuildColumnOnPlatform(GameObject parentPlatform, GameObject columnsRoot)
     {
         var randomScale = Random.Range(-3.5f, +5f);
 Vector3(column.transform.localScale.x, column.transform.localScale.y + Random.Range(-0.5f, +1f), column.transform.localScale.z);
 
         var mainChunk = Instantiate(ColumnPrefab, parentPlatform.transform.position, parentPlatform.transform.rotation);
 
         mainChunk.transform.position = new Vector3(mainChunk.transform.position.x, mainChunk.transform.position.y + (mainChunk.transform.localScale.y + randomScale) * 0.45f, mainChunk.transform.position.z);
         mainChunk.transform.localScale = new Vector3(mainChunk.transform.localScale.x, mainChunk.transform.localScale.y + randomScale, mainChunk.transform.localScale.z);
         NetworkServer.Spawn(mainChunk);
 
         var decorCount = Random.Range(1, 4);
         for (int i = 0; i < decorCount; i++)
         {
             var randomElevation = Random.Range(-1f, 0.5f);
             var randomRotation = new Vector3(Random.Range(-5.5f, 5.5f), Random.Range(10, 40), Random.Range(-5.5f, 5.5f));
 
             var decorChunk = Instantiate(ColumnPrefab, parentPlatform.transform.position, parentPlatform.transform.rotation);
 
             decorChunk.transform.position = new Vector3(decorChunk.transform.position.x, decorChunk.transform.position.y + randomElevation + (decorChunk.transform.localScale.y + randomScale) * 0.45f, decorChunk.transform.position.z);
             decorChunk.transform.rotation = Quaternion.Euler(randomRotation);
             decorChunk.transform.localScale = new Vector3(decorChunk.transform.localScale.x + Random.Range(-0.4f, 0.2f), decorChunk.transform.localScale.y + randomScale, decorChunk.transform.localScale.z + Random.Range(-0.2f, 0.22f));
             NetworkServer.Spawn(decorChunk);
         }
     }


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 N7D · Jul 22, 2018 at 06:08 PM 0
Share

So since I asked this question, I started developing awful(but I hope it will work) solution. With synclist of structures of scale values and object ids. And then setting it in ClientRPC when any client connects. Still wondering for good solution.

0 Replies

· Add your reply
  • Sort: 

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

280 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 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 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 NetworkServer.spawn, correcting my workflow: Found no behaviour for incoming Command 1 Answer

UNET 5.4 - Spawn an object from client...and move it around from client....? 1 Answer

NetworkServer.Spawn() only on Server (with registered prefabs) [Unity 5.2.3f1] 0 Answers

[UNET] Can't spawn players with code 1 Answer

Cannot Spawn networkbehaviour gameobject 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