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
0
Question by JustinC · Apr 16, 2015 at 01:53 AM · c#networkphoton

Photon Network Problems

Hello all, I am having a few issues with the photon system, I have just started messing around with this and I am following the Merry Fragmas tutorial, but I have ran into an issue. After a player dies and re-spawns, he re-spawns two instances, the second time he will spawn three instances, third is four and so on. Dont know where to even begin to find the issue, any help would be greatly appreciated, here are the scripts I am using, these are based off of the tutorial

PlayerNetworkMover

     public delegate void Respawn(float time);
     public event Respawn RespawnMe;
     
     Vector3 position;
     Quaternion rotation;
     float smoothing = 10f;
     float armor = 100f;
 
     Animator anim;
     float speed = 0.0f;
     float strafe = 0.0f;
 
     
     
     void Start () {
 
         Weapon[] weapons = GetComponentsInChildren<Weapon>();
         armor = GetComponent<Armor> ().armor;
         anim = GetComponent<Animator>();
         
         if(photonView.isMine)
         {
             gameObject.tag = "Player";
             GetComponent<CharacterController>().enabled = true;
             GetComponent<MechCharacterController>().enabled = true;
             GetComponentInChildren<Finder>().enabled = true;
             GetComponentInChildren<FollowTransform>().enabled = true;
             GetComponentInChildren<Camera>().enabled = true;
             GetComponentInChildren<AudioListener>().enabled = true;
 
         }
         else{
             StartCoroutine("UpdateData");
         }
 
     }
     
     IEnumerator UpdateData()
     {
         while(true)
         {
             transform.position = Vector3.Lerp(transform.position, position, Time.deltaTime * smoothing);
             transform.rotation = Quaternion.Lerp(transform.rotation, rotation, Time.deltaTime * smoothing);
             anim.SetFloat("Speed",speed);
             anim.SetFloat("Strafe",strafe);
             yield return null;
         }
     }
     
     void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
     {
         if(stream.isWriting)
         {
             stream.SendNext(transform.position);
             stream.SendNext(transform.rotation);
             stream.SendNext(armor);
             stream.SendNext(anim.GetFloat("Speed"));
             stream.SendNext(anim.GetFloat("Strafe"));
         }
         else
         {
             position = (Vector3)stream.ReceiveNext();
             rotation = (Quaternion)stream.ReceiveNext();
             armor = (float)stream.ReceiveNext();
             speed = (float)stream.ReceiveNext();
             strafe= (float) stream.ReceiveNext();
         }
     }
     
     [RPC]
     public void GetShot(int damage)
     {
         armor -= damage;
         if(armor <= 0 && photonView.isMine)
         {
             if(RespawnMe != null)
                 RespawnMe(3f);
             
             PhotonNetwork.Destroy (gameObject);
         }
     }



and the NetworkManager

     [SerializeField] Text connectionText;
     [SerializeField] Transform[] spawnPoints;
     [SerializeField] Camera sceneCamera;
     [SerializeField] string playerName;
 
     
     GameObject player;
     
     void Start () {
         
         PhotonNetwork.logLevel = PhotonLogLevel.Full;
         PhotonNetwork.ConnectUsingSettings ("0.1");
         
     }
     
     void Update () {
         connectionText.text = PhotonNetwork.connectionStateDetailed.ToString ();
     }
     
     void OnJoinedLobby()
     {
         RoomOptions ro = new RoomOptions (){isVisible = true, maxPlayers = 10};PhotonNetwork.JoinOrCreateRoom ("TestCell", ro, TypedLobby.Default);
     }
     
     void OnJoinedRoom()
     {
         StartSpawnProcess (0f);
     }
     
     void StartSpawnProcess (float respawnTime)
     {
         sceneCamera.enabled = true;
         StartCoroutine ("SpawnPlayer", respawnTime);
     }
     
     IEnumerator SpawnPlayer(float respawnTime)
     {
         yield return new WaitForSeconds(respawnTime);
         
         int index = Random.Range (0, spawnPoints.Length);
         player = PhotonNetwork.Instantiate (playerName, 
                                             spawnPoints [index].position,
                                             spawnPoints [index].rotation,
                                             0);
         player.GetComponent<PlayerNetworkMover> ().RespawnMe += StartSpawnProcess;
         sceneCamera.enabled = false;
     }

sorry for the huge amount of code, but as is stated before, I cannot figure out where the issue is

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

Answer by lordlycastle · Apr 16, 2015 at 03:39 AM

Posting all this code is useless, try to think; the error will definitely won’t be in start or update functions, or OnJoinRoom. It only happens when player dies, so simply follow from the code that is triggered when a player dies, and all the functions it calls. This should decrease the code significantly.

You problem is in player.GetComponent ().RespawnMe += StartSpawnProcess; This added number of times SpawnPlayer() is called, from RespawnMe event.

Comment
Add comment · Show 3 · 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 JustinC · Apr 16, 2015 at 03:45 AM 0
Share

how do i go about fixing it? i thought it might be that line but was unsure, when i tried to change it, i cannot change the operator it has to be += or -= unless it is used with in the script witch it is not

avatar image JustinC · Apr 16, 2015 at 04:07 AM 0
Share

GOT IT!!! thanks for your help. i changed the line to get the Network$$anonymous$$anager and started its StartSpawnProcess. thanks a ton i have been fighting this for two days and could not figure out what was wrong. Thank again!

avatar image MustafaBektas · Jul 30, 2016 at 06:13 PM 0
Share

Hello , How can I solve the same problem? pls link code please

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

20 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

Related Questions

Photon wont sync for the masterclient. 1 Answer

Is this bad for the network? 2 Answers

Unity3D Photon movement synchronization 0 Answers

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 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