Quantcast
Channel: Photon Unity Networking (PUN) — Photon Engine
Viewing all 8947 articles
Browse latest View live

Mmorpg on photon?

$
0
0
Hello everybody ! Sorry for my bad English , i'm French :D!

I have made a mmorpg in pixel game and now i want to do the "network part"
I read a lot about photon networking, cloud ect... and i have 2 BIG question that will decide me to create or not my game with the photon network :smile:

First, If i use photon cloud , there is a limit of 500 message/room, and i would to have 50 player in the same room ( i will change the room of the player when he change the scene (level)
is it possible? My game is a really basic Pixel game, no a lot a ressource and just basic action like Move, kill a mob, pnj ect...^^

And second , what is the best way to it ? Cloud ? or server ? because i'm a very noob with network ( I success to initialize the cloud with CCU in my game and it work ) , but try to do a server , and don't know at all how to do that T.T!
There is some tutorials about that?

Thanks for reading me ! and wish you a good day ! Ciao all :D

How to restrict the same player play against himself?

$
0
0
Let's say there is a game for the Facebook, and in the game ppl can login without facebook id, and this game has leaderboard, so each player has some score in the leaderboard. So, if the same human being will open two tabs in its browser it will be able to play against itself => earn many scores for free.
Is there some mechanism that make this impossible?

Newbie question. Why i cannt get callback "OnConnectedToMaster" from PUN

$
0
0
i am trying to make simple steps with PUN, just connect to master server, and join random room. I have setted log all info to console, and as I understand I am connectin to server, but OnConnectedToMaster is never called.


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon;
public class RandomMatchmakera : Photon.PunBehaviour {

/// <summary>
/// MonoBehaviour method called on GameObject by Unity during early initialization phase.
/// </summary>
void Avake(){
// this makes sure we can use PhotonNetwork.LoadLevel() on the master client and all clients in the same room sync their level automatically
PhotonNetwork.automaticallySyncScene = true;


}

void Start(){
// the following line checks if this client was just created (and not yet online). if so, we connect
if (PhotonNetwork.connectionStateDetailed == ClientState.PeerCreated)
{
Debug.Log ("connecting");
// Connect to the photon master-server. We use the settings saved in PhotonServerSettings (a .asset file in this project)
PhotonNetwork.ConnectUsingSettings("0.9");
}
}

public void OnJoinedLobby()
{
Debug.Log("DemoAnimator/Launcher: OnJoinedLobby() was called by PUN");
PhotonNetwork.JoinRandomRoom();
}
public override void OnConnectedToMaster()
{
Debug.Log("DemoAnimator/Launcher: OnConnectedToMaster() was called by PUN");
PhotonNetwork.JoinRandomRoom();
}

public override void OnDisconnectedFromPhoton()
{

Debug.LogWarning("DemoAnimator/Launcher: OnDisconnectedFromPhoton() was called by PUN");
}

public override void OnPhotonRandomJoinFailed(object[] codeAndMsg){
Debug.LogWarning("DemoAnimator/Launcher: Failing joining random room");
PhotonNetwork.CreateRoom (null, new RoomOptions (){ MaxPlayers = 4 }, null);
}
public override void OnJoinedRoom(){
Debug.LogWarning("DemoAnimator/Launcher: Joined room");
}


public void OnFailedToConnectToPhoton(object parameters)
{
Debug.Log("OnFailedToConnectToPhoton. StatusCode: " + parameters + " ServerAddress: " + PhotonNetwork.ServerAddress);
}
}


Here are going come logs


Server Custom Properties

$
0
0
I've (many times) gone over many documents regarding this topic, but they all appear to be outdated. The "Matchmaking guide" which I so often stumble across doesn't even work on its own right with the example code they provide.

After much research, the best I could do in terms of custom room properties was this:
string roomName;
byte maxPlayers;
PhotonNetwork.CreateRoom(roomName, new RoomOptions() {MaxPlayers = maxPlayers}, null);

And that just barely scratches the surface of what I'm trying to do. I need to be able to define map & game mode as a room property and make sure that it's able to be found in the lobby. I've tried a thousand different ways of going about this, but whatever doc I read just simply doesn't work in Unity (My only assumption is an API change occurred).

Any and all help is greatly appreciated! I just need two strings ("Map" and "Gamemode") to be defined, but I can't seem to even do that much.

newbie server / client best practice question

$
0
0
Hello All,

I am relatively new to both Unity and photon. I have completed a few of the unity tutorials and wanted to try making a simple multiplayer game. I figured I would do a multiplayer version of roll a ball where a few players connect, collect all the objects, then you win.

I started playing around with the DemoRPGMovement scene.

I created a cylinder, made it a prefab then added the "PhotonView" and "PhotonTransformView" scripts that are attached to the "Robot Kyle RPG" prefab that comes with the demo. I then added the following lines to 'DemoRPGMovement' script in the 'server' build

void CreatePickupObjects()
{
Vector3 cubePosition = new Vector3 (50, 5, 62);
GameObject newSphere = PhotonNetwork.Instantiate ("Prefab1", cubePosition, Quaternion.identity, 0);
}

for the 'client' build, I removed these lines but kept the prefab.

My question is, is it mandatory for the Cylinder prefab to be in the client build so that the connecting clients can see the prefab? ( I tried making a client build without the prefab however the that client was not able to see the cylinder I am assuming the prefab needs to be loaded somehow from the server if it is not in the client build) Or would this be bad practice similar to calculating player move speed in the client which would lead to exploitation? Obviously this does not matter when I am just learning / playing around with the demo, but I was just curious from a best practice perspective if we should keep models in client builds, or if I should keep the client to a bare minimum and research loading the prefab from the server once the client is connected (If this is the case, would anyone be able to point me to a few tutorials or keywords that I can google to find a good example?)

If my post is confusing, I uploaded a quick video to youtube.

I ran my server out of unity, and I had 2 exe's one with the prefab in the client, and one without.

image

How to get the Server Time?

$
0
0
I need the sever time.But i cant know how to get it.

namespace could not be found

$
0
0
Hello everybody !

I would like to use CrossPlatformInput in the standart assets to use a virtual joystick to make a Android game, but when i put in the script the
"if (view.isMine)
{ ......
} "

I have a error message who said ; namespace PhotonView could not be found

I add the variable : PhotonView view;

and in the start metod i add :
"{
view = GetComponent();
}"

Someone know what is happening?

Operation failed: OperationResponse 219: ReturnCode: -2 (Rpc is not enabled).

$
0
0
Hello, I have an error message that I would like to understand better, what does Rpc is not enabled mean? I presume this is an error message that is from within the Server - but since we don't use a custom Photon server what does it mean to me as a client side developer? Is this just a server issue or is there something I can do to or should be worries about?

The error message is
Operation failed: OperationResponse 219: ReturnCode: -2 (Rpc is not enabled). Parameters: {} Server: GameServer

And the stacktrace is
UnityEngine.Debug:LogError(Object)
NetworkingPeer:OnOperationResponse(OperationResponse) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1532)
ExitGames.Client.Photon.PeerBase:DeserializeMessageAndCallback(Byte[])
ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands()
ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands()
PhotonHandler:Update() (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:157)



Whenever I trigger this error this is what I suspect from the client side
  • This happens during a time when I have to send out multiple RPC calls (ending a player turn)
From the documentation online, all I can find this API page from the Photon Server platform
https://doc-api.photonengine.com/en/server/current/class_photon_1_1_load_balancing_1_1_common_1_1_l_b_error_messages.html
But it doesn't tell me anything, any insight on the error message is appreciated

Setting custom properties causes slow down

$
0
0
Hey,

I found that custom properties are causing slow downs in my game. I use them quiete a bit:
- Player died and a custom properties is increased and an RPC Die() is send to PhotonTargets.All
- Detecting cause of dead, killer and so on. If the game mode was team based the team score is updated accordingly
- The killer Kills are updated

This works fine but causes a massive slow down due to the incomming events that are being dispatched. I already changed the PhotonSendMonoTargets to my script type and it did help a lot but it still is causing a noticeable slow down.

Am I abusing custom properties? Is there a bug that is causing this? How can I handle player kills and deaths (Player customProperties) and team scores (Room customProperties) otherwise?

This makes me a bit sad because it is working so great but PhotonHandler.Update is killing it when it dispatches the incomming messages.

Check player name existance

$
0
0
A really short and straight question.
Is it possible to check a player name existance. If it exists, i want to send the player a message to choose another name.
Example. There is an inputfield. If the player puts a name in it and when he submits while the name already exists, he will get a message to type in another name because it alreasy exists. The submit button checks the photon database.

Thanks for help

PhotonNetwork.LoadLevel

$
0
0
I use Photonnetwork.LoadLevel to load the new scene. However, since the Application.LoadLevel is obsolete, is there any new implementation for Photonnetwork.Loadlevel such as Photonnetwork.LoadScene? By the way, there are different type of Loadlevel in application and SceneManager, such as LoadLevelAsync, or LoadSceneAsync. Does Photon have that kind of support?
Thanks

OnApplicationFocus to switch MasterClient

$
0
0
Hello! We are trying to make a multiplayer game. We have bots in game and all the bots are controlled by master client. The problem is that the method is not called immediately when the master client closes the application / shuts down the device / goes to the main screen. I mean the method is called after sometime but in some weird order:
1. master client closes the application / shuts down the device / goes to the main screen
2.. master client returns to the application
3. hasFocus = false
5. setMaster
4. hasFocus = true

But we need it to work in another order:
1. master client closes the application / shuts down the device / goes to the main screen
3. hasFocus = false
5. setMaster
2. previous master client returns to the application
4. hasFocus = true
  1. void OnApplicationFocus( bool hasFocus )
  2. {
  3. if (PhotonNetwork.isMasterClient && !hasFocus) {
  4. if (PhotonNetwork.otherPlayers.Length > 0) {
  5. agent.enabled = false;
  6. PhotonNetwork.SetMasterClient (PhotonNetwork.otherPlayers [Random.Range (0, PhotonNetwork.otherPlayers.Length)]);
  7. }
  8. }
  9. }
The problem seems to occur only on Android devices. We didn’t test it on iOS devices yet. Does anyone know how to solve the problem or what should we do? Thanks in advance!

Instantiating an object for only specific player(s)?

$
0
0
How can I instantiate an object but only for specific players? Something like:

PhotonNetwork.Instantiate("myObject", targetActors: new []{photonPlayer.ID, otherPhotonPlayer.ID});

Set/read network variable? (SetCustomProperties)

$
0
0
Hi, I am trying to set a custom variable (player gender). Then when a new player is detected I will read from this network variable and activate the correct player group in the prefab clone.

Can I set/get a variable with SetCustomProperties ? any example?
void FixedUpdate()
{
if (photonView.isMine)
{
//do nothing
} else {
//if their position is 0,0,0, move them to where they should be then..
//read the gender from custom properties before activation
}

Where is the best place for AI ?

$
0
0
My goal is having a small game with a few players and a few AI bots.
My question is who is usually done ?
I thought of having the host handle all the bots for example, but is that a good way to do things?
Also is there any tutorial on how to handle server based things on photon? I didnt encounter much docs about how to do things with a more server client orientation.

Assuming my idea is ok the flow should be to spawn AIs on all client, disable the AI script on all client and enable it only on host and then sync only the position/actions ?
And what about other things like collisions ? Should I let each player check his own collision ?

[help]Instantiate only working locally

$
0
0
I am really desperate, I wasted so much time trying to solve this.
Basically at start everything worked, I had 2 players with another client and it connected and spawned, then I added a lot of other code, and now when I test it everything spawn only locally for some reason.

I know it may be hard without code but really the network code is nothing, I just spawn with PhotonNetwork.Instantiate, and there is nothing else, the rest of the code is too much to post but also irrelevant.

Is there any potential reason for this to happen? Some setting in photonview, or the lobby, I don't know

sync variables

$
0
0
I want all the variables for the player to be synced on all clients so the client can click on any player and see their stats. I thought this would be as simple as syncing them all when the player is first instantiated.

void Start () {
photonView.RPC("SetAll", PhotonTargets.All);
}

[PunRPC]
void SetAll () {
gameObject.name = gameObject.name;
variables = variables;
}

It doesn't work, i can click on the enemies in the inspector and none of their variables have any values. The name isn't synced properly either, i have a UI element that displays the name of the gameobject you've clicked. How do i sync all variables on the gameObject across all players? These same gameobjects have their transform synced properly.

Problem with FriendList isOnline

$
0
0
Hi, I have a problem with PhotonNetwork.Friends list. It always says that player is online, even if I'm logged on second client with the same name. Everything is commented in code. :) Please help me ASAP ;)
Here's a code on pastebin http://pastebin.com/MftpSawv (Bad things happen at 17 line)
public void Login() //activated by button
    {
        string login = loginClass.nicknameInput.text; // get my nickname from inputfield
        string password = loginClass.passwordInput.text; // get my password from inputfield
        nickname = login; //just set variable
        PhotonNetwork.FindFriends(new string&#91;&#93; { nickname }); // find me in lobby to check if I am online
        loginClass.nicknameInput.interactable = false; // disable player to change values of inputfield
        loginClass.passwordInput.interactable = false; // disable player to change values of inputfield
    }
    public void OnUpdatedFriendList()
    {
        print(PhotonNetwork.Friends&#91;0&#93;.Name); 
        print(PhotonNetwork.Friends&#91;0&#93;.IsOnline); // show my status 
        StartCoroutine(CheckIfLogged()); 
    IEnumerator CheckIfLogged()
    {
        if (PhotonNetwork.Friends&#91;0&#93;.IsOnline) // check if my nickname is already in lobby (here's error,
        {                                      //it is always false, even if i am logged in another client of game
            loginClass.nicknameInput.text = ""; //reset nickname inputfield
            loginClass.passwordInput.text = ""; //reset password inputfield
            loginClass.Warning.text = "Already logged!"; // show warning 
            yield return new WaitForSeconds(1.0f);
            loginClass.Warning.text = ""; // reset wawning text
            loginClass.nicknameInput.interactable = true; //enable player to change values of inputfield
            loginClass.passwordInput.interactable = true; //enable player to change values of inputfield
        }
        else
        {
            PhotonNetwork.playerName = nickname; // set my nickname
            SetMenuState(2); // switch to main menu
        }
    }

How to damage others but ignore self

$
0
0
Hello there! I really like Photon so far, but I'm pretty new to it so I have some issues at the moment in regards to specific players taking damage etc.

So the way it currently works is that every player is syncing their health with this:
void Update()
{
if (!m_PhotonView.isMine)
{
playerHealth.setHealth(health);
}
else
{
health = playerHealth.getHealth();
}
}

public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
stream.SendNext(health);
stream.SendNext(anim.GetFloat("m_MoveSpeed"));
}
else
{
health = (int)stream.ReceiveNext();
anim.SetFloat("m_MoveSpeed", (float)stream.ReceiveNext());
}
}
That seems to work ok, but what I want to do is for example to have one player cast a meteor, but I only want the meteor to be able to damage all players except for the one who cast it.
I can't seem to figure out a way for the meteor to not damage the one who cast it. Right now I'm instantiating it with PhotonNetwork.Instantiate and then the meteor has a script on it that basically just checks everyone it collides with and deducts the damage from the HP.
How would I make it so that the meteor ignores the player that cast it fully? I've tried with PunRPC but no matter how I wrote it I couldn't get it to work properly. It would either damage the wrong player or all players.

If you need more information let me know. I really hope someone can help me with this as I haven't been able to search my way out of it :(

IPunCallbacks without a MonoBehaviour

$
0
0
Is there a built in way to receive IPunCallbacks on objects which are not MonoBehaviours?

I suppose looking through the code I could add a method to PhotonNetwork to register the IPunCallback objects, and then update NetworkingPeer.SendMonoMessage to accomplish this, but it feels like there should be an officially supported option.
Viewing all 8947 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>