Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. We're looking for your feedback on the platforms you use and how you use them. Let us know!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  5. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  6. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Photon Unity Networking

Discussion in 'Connected Games' started by tobiass, Aug 23, 2011.

  1. Kurtav

    Kurtav

    Joined:
    May 24, 2015
    Posts:
    79
    One customer in UpWork wrote me the following sentence -
    "The reason I am using Gamesparks is that there is no cost to use it up to 100k monthly users. For PUN there is only 20 CCU which I will easily go over just in beta testing."
    0_o
    I do not understand why such different prices? What is the key difference? Explain, please
     
  2. JohnTube

    JohnTube

    Joined:
    Sep 29, 2014
    Posts:
    38
    Hi @Kurtav,

    We have answered your question on our forum here.
     
    Kurtav likes this.
  3. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    822
    Yikes! That's quite a difference. PUN does seem to be excellent value by comparison.
     
  4. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    720
    I haven't even heard of game spark until now. Thanks for that explanation though regardless. Incase I would of been tricked later on if I came across that company. The cost of photon is pretty dang cheap that's why I use it. My last game made $96,000 with 500 players. Only 50 of them were paying players that year. If your game can't cover pun cost then your business model for your game needs to be relooked at.

    Also I really love Photon API.
    Ever looked at UNET code? its like way more complicated.
     
  5. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,377
  6. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    822
    Each one of the 50 paying customers shelled out $1920 dollars to play the game, that's some pretty impressive ROI by any standards.
     
    JohnTube likes this.
  7. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    720
    Hey Munchy. Yup. Most are to afraid to charge for your games.

    Anyways why is PhotonTransformView still uneditable during play mode? This is so frustrating!
    I'm needing to assign things dynamically :(
    I was told this was gonna get changed a year ago.

    I literately can not think of any reason why someone would want to add PhotonView, PhotonTransformView, PhotonAnimatorView manually on every network object in their game.
    I"m gonna have thousands of objects eventually.
     
  8. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    1,964
    @Shadowing: I fear that we lost track of the feature to be able to edit PhotonTransformView during runtime. Sorry.

    You should consider the PhotonTransformView just as one possible solution to your problem though. It's a IPunObservable class and if you make your own (copy and rename), you can modify it any way you like. In our experience, it makes sense to have your own way to sync and smooth movement in quite a lot of cases.

    @renman3000: Yes, that solution is valid and has no sideeffects. It will be in the next updates.
     
  9. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    720
    Doesn't this always get called.
    Right now I have a new version of PhotonTransformView named MyPhotonTransformView
    and this is never being called on that script.
    PhotonView component is observing it as well.

    Code (csharp):
    1.  
    2.     public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) {
    3.  
    4.              Debug.Log("Test")
    5.  
    6.     }
    7.  
    I have RPC calls all working correctly. As in finding other players by photon ID and making a player aim or jump etc..

    I don't know why i can't get stream working with loading scripts during run time.
     
    Last edited: Aug 9, 2018 at 10:04 AM
  10. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    822
    Have you considered using RaiseEvent instead. Doesn't rely on PhotonViews or any of the other ready rolled networking stuff, so scripts can be easily added/removed/enabled/disabled at runtime as needed and you have complete control over how, when and to which clients you send data.
     
  11. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    720
    Never heard of it Munchy

    So now im using this script.
    Shouldn't my Debug.Log("test")
    be spamming the heck out of my console during run time?

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. public class PhotonNetworkMover : Photon.MonoBehaviour {
    5.     float smoothing = 1f;
    6.     // Use this for initialization
    7.     void Start () {
    8.         if (photonView.isMine) {      
    9.         }else{
    10.             StartCoroutine("UpdateData");
    11.         }
    12.    
    13.     }
    14.     IEnumerator UpdateData()
    15.     {
    16.         while (true)
    17.         {
    18.             transform.position = Vector3.Lerp(transform.position, position, Time.deltaTime * smoothing);
    19.             transform.rotation = Quaternion.Lerp(transform.rotation, rotation, Time.deltaTime * smoothing);
    20.             yield return null;
    21.         }
    22.     }
    23.     void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info){
    24.         Debug.Log("test");
    25.         if(stream.isWriting){
    26.             stream.SendNext(transform.position);
    27.             stream.SendNext(transform.rotation);
    28.         }else{
    29.             position = (Vector3)stream.ReceiveNext();
    30.             rotation = (Quaternion)stream.ReceiveNext();
    31.         }
    32.     }
    33.    
    34. }
    35.  
     
  12. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    720
    Well it turns out if I add photon view and photonTransformView to my prefab before run time everything works fine.
    Thats with me not using Photon.Instantiate and just using regular Instantiate on all clients.

    So I at least ruled out it not having to do with me assigning my own ID's etc..
    Also placing debug inside streaming spams my console log now.


    So the problem I have now is being able to add photon view and PhotonTransform during run time.
    If I do this some reason OnPhotonSerializeView() never gets called. Either on PhotonTransformView or the NetworkMover script I made.


    Here is one way I've tried doing it.

    Code (csharp):
    1.  
    2. GameObject CharacterPrefab = Resources.Load("Playable Characters/Characters/" + MyFunctions.FirstLetterToUpper(GameSettings.UserData["general"]["race"].Value)) as GameObject;
    3.  
    4. PhotonView m_PhotonView = CharacterPrefab.AddComponent<PhotonView>();
    5. MyPhotonTransformView m_PhotonTransformView = CharacterPrefab.AddComponent<MyPhotonTransformView>();
    6. m_PhotonTransformView.m_PositionModel.SynchronizeEnabled = true;
    7. m_PhotonTransformView.m_RotationModel.SynchronizeEnabled = true;
    8. CharacterPrefab.GetComponent<PhotonView>().ObservedComponents.Add(m_PhotonTransformView);
    9.  
    10. player = Instantiate(CharacterPrefab, new Vector3(3000, 3000, 3000), new Quaternion());
    11.  
    I do add some logic im not showing here to prevent duplicate components being added to the prefab.
    So this code works. Adds the components and assigns just fine. No issues there except OnPhotonSerializeView() never gets called. Even if I use my NetworkMover script as shown in my above post.

    Also tried adding the components after Instantiate.

    Maybe cause I can't changed observed components during run time?
    I'll do a test to test that theory out.


    Edit: ya I just confirm. the issue is assigning observed components to PhotonView during runtime. How do I get around that issue? Is there anything in the api that I need to run to update observed components?
     
    Last edited: Aug 9, 2018 at 1:06 PM
  13. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    822
  14. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    720
    Oh thanks Munchy I wasn't aware of that. That just another way of doing a RPC though. I don't have any issues with using RPC with dynamicly adding the PhotonView component.
    Its not a altnerate way to stream data.

    Maybe I should stop even using streaming and just use RPC with lerping for movement.

    @tobiass when using photon chat does each channel work like photon pun rooms? Where it uses a seperate cloud instance? Or does all channels use the same instance and it's just routing the channels?

    I built a low level API to use with photon chat that should allow hundreds of players to stay in sync. Seems to work very well and uses extremely little data.

    I was going to use photon pun for when players are grouped. To sync the players inside the group and enemies but also still sync players out side the group with photon chat.

    But if photon chat channels are instances like rooms. Then I'm thinking I should just use photon chat for everything and lerp rotations
     
  15. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    1,964
    @Shadowing: Technically, it should be possible to manually instantiate a networked game object and to assign a observed component to it.

    Re-reading your earlier post, I think I found what was happening in that case:
    In the code, you create a GO, which is then used as prefab to instantiate. You are adding components to the prefab and you're using concrete instances to wire them up with one another. Then you instantiate and I think this is where things fail: You setup a concrete instance which is duplicated in the instancing. The problem here: The references you set on the instances are not adjusted to the instances used in the duplicate (new instance).

    Prefab components can be setup to observe one another and Unity will resolve this into a concrete instance, when you call Instantiate. This is probably not the case here, as you're not pointing prefabs to one another and your wiring gets lost.

    Instantiate first, then setup the new instance's wiring and observed list with the concrete components.

    If that's not it, please make a minimal repro case, upload to dropbox or similar and mail the link to: developer@photonengine.com and we have a look.


    @Munchy2007 thanks for all the input! :)

    In the end, RPCs as well as OnSerializePhotonView() will both create events. While RPCs are called reactively, there is a predefined frequency for OnSerializePhotonView() updates. As PUN does, you can build both solutions with the underlying events.
    Using RaiseEvent can make sense when you want to control what's in the events or when you don't use networked objects anyways. I hope this page explains this up somewhat.
     
  16. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    720
    Does two channels in Photon Chat share the same Load?

    Ya it doesn't matter if i try to add the components to the prefab or add it after I Instantiate it.
    Its the same result in OnSerializePhotonView never being called.
    I don't have any issues with RPC's

    Oh well I just decided to only use OnSerializePhotonView for playable characters only and not for AI. I'll get better performance that way anyways. Won't have to worry about hitting the data limit that way.
     
  17. Smart-hawk1

    Smart-hawk1

    Joined:
    May 23, 2017
    Posts:
    146
    To clarify something,

    The OnSerializeView will only send data when the data is changed?

    for example,
    if we're sending bool (Input.getKey)
    it will only be sent when this bool changes locally to false or true?? so I don't have to make an if statement inside the onserializeview to manually check when the bool is changed?
     
  18. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    1,964
    @Shadowing: If you are interested in a solution, please send us a way to reproduce this. Can be via text, too.
    Mail to: developer@photonengine.com please. Thanks.

    @Smart-hawk1: OnSerializePhotonView will only send something if it did add data to the stream. It does not check if values are changed, unless you select the sync mode "reliable delta compressed", which is not optimal in most cases.

    Your code has to figure out which values it needs to send.
     
  19. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    720
    @tobiass I read somewhere that you mentioned something about pun can handle around 400 RPC requests at a time. At least until you tell us we are over loading it.
    Is that true. If thats true I really don't need to use photon chat for movement between 300 players. If I'm only using RPC.

    I was going to use 300 for players and 100 for AI when only in a group.

    You think Photon Server will ever have a Linux solution? I'm really wanting that badly.
     
  20. Smart-hawk1

    Smart-hawk1

    Joined:
    May 23, 2017
    Posts:
    146


    Code (CSharp):
    1. void OnSerializePhotonnView(PhotonStream stream, PhotonMessageInfo info)
    2. {
    3.     {
    4.         stream.SendNext(MyBool);
    5.     }
    6.     else
    7.     {
    8.         MyBool = (bool) stream.ReceiveNext();
    9.     }
    10. }
    In this case, if "MyBool" is always true, it will keep sending data right saying this bool is true? I thought because I checked "Unreliable On Change" it will only send this bool if it changed to true or false.
     
  21. digiross

    digiross

    Joined:
    Jun 29, 2012
    Posts:
    136
    I'm completely new to photon and wondered if I can add it to my existing project (about 35% complete) without a whole lot of trouble or would I be better served starting over with a brand new photon project. Your thoughts please.