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
1
Question by Pr0n · Jan 15, 2015 at 05:33 AM · 2dnetworkingrpcnetworkview

OnSerializeNetworkView issus in my 2D game

Hello :)

I have 2 Scripts:

  1. NetworkManager

  2. PlayerScript

and GameObject Player: alt text

for control network i have GameObject Scripts:

alt text

PlayerScript code:

 sing UnityEngine;
 using System.Collections;
 
 public class PlayerScript : MonoBehaviour {
 
     public float speed = 10f;
     
     private float lastSynchronizationTime = 0f;
     private float syncDelay = 0f;
     private float syncTime = 0f;
     private Vector3 syncStartPosition = Vector3.zero;
     private Vector3 syncEndPosition = Vector3.zero;
 
 
     private void InputMovement()
     {
         if (Input.GetKey(KeyCode.W))
             rigidbody2D.MovePosition(rigidbody2D.position + Vector2.up * speed * Time.deltaTime);
         
         if (Input.GetKey(KeyCode.S))
             rigidbody2D.MovePosition(rigidbody2D.position - Vector2.up * speed * Time.deltaTime);
         
         if (Input.GetKey(KeyCode.D))
             rigidbody2D.MovePosition(rigidbody2D.position + Vector2.right * speed * Time.deltaTime);
         
         if (Input.GetKey(KeyCode.A))
             rigidbody2D.MovePosition(rigidbody2D.position - Vector2.right * speed * Time.deltaTime);
     }
 
     void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
     {
         Debug.Log("OnSerializeNetworkView!!!!!!!!!!!!!!!!!!!!");
         Vector3 syncPosition = Vector3.zero;
         Vector3 syncVelocity = Vector3.zero;
         if (stream.isWriting)
         {
             syncPosition = rigidbody2D.position;
             stream.Serialize(ref syncPosition);
             
             syncPosition = rigidbody2D.velocity;
             stream.Serialize(ref syncVelocity);
         }
         else
         {
             stream.Serialize(ref syncPosition);
             stream.Serialize(ref syncVelocity);
 
             syncTime = 0f;
             syncDelay = Time.time - lastSynchronizationTime;
             lastSynchronizationTime = Time.time;
             
             syncEndPosition = syncPosition + syncVelocity * syncDelay;
             syncStartPosition = rigidbody2D.position;
         }
     }
 
     void Awake()
     {
         lastSynchronizationTime = Time.time;
         
     }
     
     void Update()
     {
         if (networkView.isMine)
         {
             InputMovement();
         }
         else
         {
             SyncedMovement();
         }
     }
 
     
     private void SyncedMovement()
     {
         syncTime += Time.deltaTime;
         
         rigidbody2D.position = Vector3.Lerp(syncStartPosition, syncEndPosition, syncTime / syncDelay);
         Debug.Log(syncStartPosition+ " ####### " +rigidbody2D.position+ " ####### " +syncEndPosition);
     }
 
 }


and NetworkManager code:

 using UnityEngine;
 using System.Collections;
 
 public class NetworkManager : MonoBehaviour {
 
     public Transform point1;
     public Transform point2;
 
     public GameObject player;
 
     // Use this for initialization
     void Start () {
         if (Network.isServer) {
             Network.Instantiate(player,point1.transform.position,Quaternion.identity,0);    
         }
     }
 
     void OnPlayerConnected ( NetworkPlayer netPlayer)
     {
         networkView.RPC("net_DoSpawn",RPCMode.All);
     }
 
     [RPC]
     void net_DoSpawn()
     {
         Network.Instantiate(player,point2.transform.position,Quaternion.identity,0);
     }
 }



I tried many times to debug id, but no change. OnSerializeNetworkView isnt called and player are spawnet twice.. If Iam traing to go to other players positions they start flashing, otherwise they are not visible.. Anybody can halp me please? A lot of thanks and sorry for my english :))

capture.png (70.8 kB)
capture2.png (28.0 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

3 Replies

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

Answer by AlexTudo · Apr 18, 2015 at 05:07 PM

First thing I notice that you missed is the fact that if you use OnSerializeNetworkView you need to change the 'observed' object of the NetworkView to the script and not the transform as in picture below.

alt text

Also, I think you wanted 'syncVelocity' in the second call below.

     if (stream.isWriting)
     {
         syncPosition = rigidbody2D.position;
         stream.Serialize(ref syncPosition);
                  
         syncPosition = rigidbody2D.velocity; //<--syncVelocity
         stream.Serialize(ref syncVelocity);
     }

Let me know what happens next after the changes.


1.png (27.4 kB)
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
avatar image
0

Answer by hannah112 · May 18, 2018 at 12:56 PM

2D has discovered a home basically in the easygoing gaming market, which has been regularly disregarded regardless of it being an extensive market. So PC recreations and applications for versatile and tablet will regularly have 2D amusements. Online Shopping deals in pakistan. Particularly if the diversions are by outside the box designers as it is a less expensive generation cost for them.

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
avatar image
0

Answer by stupidwolf99 · Apr 17, 2020 at 09:19 AM

The scope of 2D graphics and animation is still very vast. Online Shopping in Pakistan The requirement of 3d has grown for the last years but 2D still has it's own share of market.,The scope of 2D graphics and animation is still very vast. gaming is still Online Shopping in Pakistan The requirement of 3d has grown for the last years but 2D still has it's own share of market.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

RPC or Synchronization ? 1 Answer

Where is a free, helpful tutorial on how to use Unity's networking? 2 Answers

Is server the sender of RPC? 0 Answers

networkView.RPC() inside a ScriptableObject 1 Answer

Which is better: NetworkView or RPC? 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