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

PhotonNetwork OnParticleCollision(GameObject Other)

$
0
0
Hello all, I've been having a blast using photon networking and have nearly finished my game. A battle royale game similar to PUB-G but with a twist (ed metal) 8P, its vehicles! I have made it pretty far and I am on the final stages of tweaking weapons. I was using Ray Casting but decided to go with particles as I like the more realistic feel they give. Currently OnParticleCollision is working but when I try to get the name of the particle so I am able to properly set the damage float according to which particle hit it doesn't return the particles name. Here is the code I am using. Hope you can help!

this is my firing script which works properly.




void OnParticleCollision(GameObject other)
{
Transform hitTrans;
hitTrans = other.gameObject.transform;
if(hitTrans.gameObject.name == "Flame")
{
this.GetComponent().RPC("TakeDamage", PhotonTargets.AllBuffered, sideDamage);
}
if (hitTrans != null)
{
if (hitTrans.name == "Flame")
{
this.GetComponent().RPC("TakeDamage", PhotonTargets.AllBuffered, sideDamage);
}
}

if (other.name == "Fire" && view.isMine)
{
this.GetComponent().RPC("TakeDamage", PhotonTargets.AllBuffered, AtomBombDamage);
}
if (other.name == "Flame" && view.isMine)
{
this.GetComponent().RPC("TakeDamage", PhotonTargets.AllBuffered, sideDamage);
}
if(other.transform.name.ToString() == "Flame")
{
this.GetComponent().RPC("TakeDamage", PhotonTargets.AllBuffered, sideDamage);
}

How can I get room creation time

$
0
0
Because PhotonNetwork.time is incorrect sometimes I cant use CustomRoomProperties to set room creation time

I just need it to make SYNCED ROOM TIME

So is there another way to get it

PhotonNetwork.time is not synchronized

$
0
0
I faced strange behavior:

PhotonNetwork.time is synchronized in proper way in Editor/Standalone build, but
when I run it under iOS devices PhotonNetwork.time is different from sever timestamps dramatically (millions)

What can cause this problem?

I am using PhotonServer on standalone machine and free PUN from asset store...

On iOS I got negative values.

Server time double: -1155847.248
Server time ms: -1155847248

Server time that I got via RPC is: 3137684
PhotonNetwork.FetchServerTimestamp() - does not help...

Very strange that it reproducible on iOS actual device only (not in editor/nor standalone build for win/mac)

BTW, in editor I got following:

Server time double: 3139752.208 (using PhotonNetwork.time)
Server time ms: -1155215088 (using PhotonNetwork.networkingPeer.ServerTimeInMilliSeconds)


I think the problem is near....

Somehow on iOS the following line in getter produce NEGATIVE value:

public static double time
{
...
return ((double)(uint)networkingPeer.ServerTimeInMilliSeconds) / 1000.0f;
...
}

Missing info on some Photon Transform View settings

$
0
0
Hi,
You appear to be missing some info in your docs on some of the options of the Photon Transform View. Specifically, how does "Lerp Speed" work, and what does checking "Draw synchronized position" do?

In unity, lerp is a value between 0 and 1 that determines the point between two values that should be returned. How does "speed" work? The only reference I can find is in one of your tutorials that simply says "set this to 10, higher values make the object catch up faster." That's not really much of an explanation as to how it actually works.

And as far as "Draw synchronized position", I can find anything anywhere on this. What does it do and does this only affect things if extrapolation is enabled?

Fastest Way To Destroy

$
0
0
What's the fastest way to kill a player? I tried PhotonNetwork.Destroy, it's fast for master client but very slow for clients.

How to send a struct with PunTurnManager

$
0
0
Hi, I'm making a turnbased card game, I make all mechanics of the game, but I can't send the struct that includes the deck, the hand for each player , the cards in the table. The hand are a struc that includes a vector of another struct, I try to send with a instruction like this : "this.turnmanager.sendmove(MessageStruct);", but I can't send and receive it, so my question is: how I can send all struct? Or is it impossible to send?

there is the code of the structs:


struct cards
{
internal string value, suit;
}

struct hand
{
cards[] hand;
bool finishedcard; // for verify if the hand is empy
}

struct Message
{
List Table;
List Deck;
Hand LocalPlayer, RemotePlayer;
Stack StackLocal, StackRemote;
}

Message CardPack;

public void MakeTurn()
{
this.turnmanager.sendmove(CardPack);
}


thanks for the answer

How to send a struct with PunTurnManager

$
0
0
Hi, I'm making a turnbased card game, I make all mechanics of the game, but I can't send the struct that includes the deck, the hand for each player , the cards in the table. The hand are a struc that includes a vector of another struct, I try to send with a instruction like this : "this.turnmanager.sendmove(MessageStruct);", but I can't send and receive it, so my question is: how I can send all struct? Or is it impossible to send?

there is the code of the structs:


struct cards
{
internal string value, suit;
}

struct hand
{
cards[] hand;
bool finishedcard; // for verify if the hand is empy
}

struct Message
{
List Table;
List Deck;
Hand LocalPlayer, RemotePlayer;
Stack StackLocal, StackRemote;
}

Message CardPack;

public void MakeTurn()
{
this.turnmanager.sendmove(CardPack);
}


thanks for the answer

Can't connect on server from android client (works on windows)

$
0
0
Hello,

I have a strange bug, I tested it with a custom project and the PUN demos, all works fine on a Windows client, but when I want to connect to server from an Android client, I have this error:

<i>AndroidPlayer(Xiaomi_Redmi_4A@192.168.1.73)</i> Receive issue. State: Connected. Server: '127.0.0.1' ErrorCode: 10061 SocketErrorCode: ConnectionRefused Message: Connection refused System.Net.Sockets.SocketException: Connection refused at System.Net.Sockets.Socket.Receive (System.Byte[] buffer) [0x0004d] in /Users/builduser/buildslave/mono/build/mcs/class/System/System.Net.Sockets/Socket.cs:2373 at ExitGames.Client.Photon.SocketUdp.ReceiveLoop () [0x00000] in <filename unknown>:0

I have no idea why Photon try to connect to localhost, I set my photon server settings with the server ip.
Note that I host my server myself as I want my smartphone to connect on the server in LAN.
I also set the player settings to require internet on android.

I use PUN Free, Unity 2017.2 and Android 7.0. Any idea on what could be wrong ?

Thanks a lot for any help.

waiting room countdown trouble

$
0
0
Hello all, I'm having a little trouble on sending countdown timer with RPC.
I have a waiting room which all connected (to the room) players gather in list. So when Player 1 creates room and waits other players to join. Until 60 sec countsdown. Debug.Log works but timer starts to down on each player individually
using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class TestLobby : MonoBehaviour {

	public PhotonView pv;
	public float timer = 60f;
	public Text t;


	void Start ()
	{
		
	}

	void Update ()
	{
		if (PhotonNetwork.inRoom) {
			if (PhotonNetwork.isMasterClient) 
			{
				pv.RPC ("ShowTimer", PhotonTargets.All);
				Debug.Log ("Chek for sending an RPC");
			}
		} 
		else 
		{
			timer = 60f;
		}
	}
		

	[PunRPC]
	public void ShowTimer ()
	{
		timer -= Time.deltaTime;
		t.text = "Game Begins In: " + timer.ToString ("f0");
		Debug.Log ("Check for receiving an RPC");
	}
}

Cross-Platform UWP XboxPC support

$
0
0
Hi,

I'm wondering if Photon supports cross-platform support for a UWP game running on Xbox and PC. I see a lot about cross-platform support for Android and iOS, but I haven't seen anything about this particular configuration - I'm sorry if I missed it.

Pun 2 Beta Early Access [December 2017]

$
0
0
Hi Everyone,

We are releasing a beta package of our next PUN version ( will be referred as PUN 2 ) featuring major internal changes, API changes as well as performances and optimization improvements, while retaining the same design pattern principles ( PhotonViews, RPC, Cloud, etc)

You can download it here

Few things to know:

- This version is NOT READY FOR PRODUCTION, use it at your own risk.
- Unity 5.3.7 is the minimal version

Known Issues:

- Only UDP type connection works, TCP and web socket are not leveraged yet

New Features:

- Improved Namespace to avoid clash with other assets
- LoadBalancing (LB) api has been revamped for a better separation between PUN and LB
- The PUN API changed in numerous place
- Performance and optimization is improved with less caching of data and better memory usage to avoid unnecessary allocations where possible.
- Explicit registration for PUN callbacks is now necessary, although automated when using 'PunBehaviour' ( watch out when overriding OnEnable() and OnDisable() you must call the base or registration will not occur
- Demos now using the Unity UI system instead of the deprecated one which had a very design pattern for coding.

Future Features:

- Documentation overall pass to cover all changes and new features
- Completed Demos
- Network Prefab will no longer be required as a Resource but will need explicit registration
- More optimizations and performances improvements

We welcome your feedback on this :)

I'd suggest you keep it in that thread, but if you make a new thread, make sure you mention "Pun 2" so we know where we are.

Bye,

Jean

Current server outage?

$
0
0
We're currently seeing a server outage (EU region), our friends from the US report the same.

Help?

TimeoutDisconnect while connecting. Check if the server is available.

$
0
0
I have been using Photon for the past few weeks, and this is the first time I can't seem to connect.
I get this error:
TimeoutDisconnect while connecting to: 37.58.80.136:5055. Check if the server is available.
I don't believe I changed anything, so maybe its server side? But why would the server not be avaliable?
Thanks!

Edit: I also get this error "Cause: DisconnectByClientTimeout", if that helps

Clients movement is not showing in the Master

$
0
0
The following code is for spawning a playerprefabs and assigning buttons for each prefab to jump.

I'm assuming Master as Editor and Client as executable.
When objects in master jumps it is seen in client but when client's objects jump it is not updated in master.
Please help someone. I'm kinda stuck with it :(

Check the link for screenshot of the Scene view.
https://drive.google.com/file/d/1TEaW8gbc0BDrK_lP_3Ciec5cJhuRliCK/view?usp=sharing
public class PlayerNetwork : Photon.MonoBehaviour {

	public static PlayerNetwork instance;
	public string PlayerName {get;private set ;}
	private PhotonView PhotonView;
	private int PlayersInGame=0,id1,id2;
	public GameObject Player;	
	private Transform PlayerFormation,TargetFormation;
	private PlayerController a, b, c,x,y,z;
	private Button a1,b1,c1,x2,y2,z2;
	void Awake ()
	 {		
		instance=this;
		PlayerName="Gamer#"+Random.Range(1000,9999);
		PhotonView=GetComponent<PhotonView>();		
		SceneManager.sceneLoaded+=OnSceneFinishedLoading;		
	}
	
	private void OnSceneFinishedLoading(Scene scene, LoadSceneMode mode)
	{
		if (scene.name=="test")
		{
			if (PhotonNetwork.isMasterClient)
			{
				MasterLoadedGame();
			}
			else
			{
				NonMasterLoadedGame();
			}
		}
	}
	
	private void MasterLoadedGame()
	{
		PhotonView.RPC("RPC_LoadedGameScene",PhotonTargets.MasterClient);
		PhotonView.RPC("RPC_LoadGameOthers",PhotonTargets.Others);				
	}

	private void NonMasterLoadedGame()
	{
		Debug.Log("NonMaster function Called");
		PhotonView.RPC("RPC_LoadedGameScene",PhotonTargets.MasterClient);
	}

	[PunRPC]
	private void RPC_LoadGameOthers()
	{
		PhotonNetwork.LoadLevel(1);
	}

	[PunRPC]
	private void RPC_LoadedGameScene()
	{
		PlayersInGame++;
		if (PlayersInGame==1)
		{
			PhotonView.RPC("RPC_SpawnPlayerCamera",PhotonTargets.MasterClient);
			PhotonView.RPC("RPC_SpawnPlayers",PhotonTargets.MasterClient,id1);			
			PhotonView.RPC("RPC_AssignPlayerButtons",PhotonTargets.MasterClient);						
		}
		else if (PlayersInGame==2)
		{	
			PhotonView.RPC("RPC_SpawnTargets",PhotonTargets.MasterClient,id2);						
			PhotonView.RPC("RPC_SpawnTargetCamera",PhotonTargets.Others);						
			PhotonView.RPC("RPC_SpawnTargets",PhotonTargets.Others,id2);
			PhotonView.RPC("RPC_SpawnPlayers",PhotonTargets.Others,id1);					
			PhotonView.RPC("RPC_AssignTargetButtons",PhotonTargets.Others);			
		}
		if (PlayersInGame==PhotonNetwork.playerList.Length)
		{
			print("All players are in game");			
		}
	}

	[PunRPC]
	private void RPC_SpawnPlayerCamera()
	{		
		Camera.main.transform.position=new Vector3(0f,2f,-7f);
		Camera.main.transform.rotation=Quaternion.Euler(15f,0f,0f);		
	}

	[PunRPC]
	private void RPC_SpawnTargetCamera()
	{	
		Camera.main.transform.position=new Vector3(0f,2f,7f);
		Camera.main.transform.rotation=Quaternion.Euler(15f,180f,0f);
	}

	[PunRPC]
	public void RPC_SpawnTargets(int id2)
	{
		int i = 1;
		id2=100;
                TargetFormation=GameObject.Find("Target Formation").GetComponent<Transform>();
		foreach (Transform child in TargetFormation ) 
		{
			GameObject target =Instantiate(Player,child.transform.position,Quaternion.identity) as GameObject;
			target.name = "Target ("+i+")";
			target.transform.parent = child;			
			PhotonView[] nViews = target.GetComponentsInChildren<PhotonView>(); 
    		        nViews[0].viewID = id2;
			id2++;			
			i++;
		}
		i = 0;
	}

	[PunRPC]
	public void RPC_SpawnPlayers(int id1)
	{
		int i = 1;
		id1=50;
		PlayerFormation=GameObject.Find("Player Formation").GetComponent<Transform>();
		foreach (Transform child in PlayerFormation ) 
		{
			GameObject player = Instantiate(Player,child.transform.position,Quaternion.identity) as GameObject;
			player.name = "Player ("+i+")";
			player.transform.parent = child;			
			PhotonView[] nViews = player.GetComponentsInChildren<PhotonView>(); 
    		        nViews[0].viewID = id1;
			id1++;
			i++;
		}
		i=0;
	}

	[PunRPC]
	private void RPC_AssignPlayerButtons()
	{
		a = GameObject.Find("Player (1)").GetComponent<PlayerController>();       
                b = GameObject.Find("Player (2)").GetComponent<PlayerController>();      
                c = GameObject.Find("Player (3)").GetComponent<PlayerController>();
		a1=GameObject.Find("P1 Jump").GetComponent<Button>();
                a1.onClick.AddListener(a.Jump);
                b1=GameObject.Find("P2 Jump").GetComponent<Button>(); 
                b1.onClick.AddListener(b.Jump);       
                c1=GameObject.Find("P3 Jump").GetComponent<Button>(); 
                c1.onClick.AddListener(c.Jump);		
	}

	[PunRPC]
	private void RPC_AssignTargetButtons()
	{
		x = GameObject.Find("Target (3)").GetComponent<PlayerController>();       
                y = GameObject.Find("Target (2)").GetComponent<PlayerController>();      
                z = GameObject.Find("Target (1)").GetComponent<PlayerController>();
		x2=GameObject.Find("P1 Jump").GetComponent<Button>();
                x2.onClick.AddListener(x.Jump);
                y2=GameObject.Find("P2 Jump").GetComponent<Button>(); 
                y2.onClick.AddListener(y.Jump);       
                z2=GameObject.Find("P3 Jump").GetComponent<Button>(); 
                z2.onClick.AddListener(z.Jump);
	}
	
}

How would I do this in PUN?

$
0
0
I have a mobile game where the local player is always on the bottom of the screen next to the game controls, but I'm trying to figure out how to make them show up on one of three spawn points (left, top, or right) on everyone else's screen when they're not the local player, the gameobject they control is a turret and the only thing that needs to be sent is the rotation since their position will be different and will always be on the bottom on their own screens.

I've tried using PhotonNetwork.Instaniate and then setting up PhotonView on the gameobject but when I instantiate them on their main position (bottom), it instantiates all the players on the bottom.

Since that didn't work I tried instead to instaniate the gameobject locally on Unity and then for each player that's in the room it would instantiate another gameobject locally starting on the left spawnPoint and going clockwise, but the problem with doing this is that the photonview owner is set to "scene" and I can't get the cannon's rotation. Am I going about this the wrong way? I'm new to PUN and still trying to wrap my head around how everything fits together.

PhotonNetwork.GetRoomList() returning zero.

$
0
0
Hi,
Master client creates room using
PhotonNetwork.CreateRoom(name,
             new RoomOptions() { isVisible = true, isOpen = true, maxPlayers = (byte)maxPlayersCount }, TypedLobby.Default)
. But from the client side even after doing the initial setup of photon I log the rooms count here
public override void OnReceivedRoomListUpdate()
    {
        Debug.Log("OnReceivedRoomListUpdate called");

        if (m_notifier != null)
        {
            m_notifier.OnSessionListRefreshed();
            RoomInfo[] roomsList = PhotonNetwork.GetRoomList();
            Debug.Log(" OnReceivedRoomListUpdate Room list count" + roomsList.Length);
        }
    }
But still the length is zero and i have Auto Join lobby true in settings.

Pleas help!

Networking Issue

$
0
0
What could be the reason for client's transform not updating in master server?

These 4 RPCs has been called in my script. But still if a player in client-side move, it is not updating in server but server-side movements are updating in client. Somebody please help!

               if (PlayersInGame==1)
		{
			PhotonView.RPC("RPC_SpawnPlayerCamera",PhotonTargets.MasterClient);
			PhotonView.RPC("RPC_SpawnPlayers",PhotonTargets.MasterClient,id1);			
			PhotonView.RPC("RPC_AssignPlayerButtons",PhotonTargets.MasterClient);									
		}
		else if (PlayersInGame==PhotonNetwork.playerList.Length)
		{	
			PhotonView.RPC("RPC_SpawnTargets",PhotonTargets.MasterClient,id2);
			PhotonView.RPC("RPC_SpawnTargetCamera",PhotonTargets.Others);
			PhotonView.RPC("RPC_SpawnTargets",PhotonTargets.Others,id2);					
			PhotonView.RPC("RPC_AssignTargetButtons",PhotonTargets.Others);		
			PhotonView.RPC("RPC_SpawnPlayers",PhotonTargets.Others,id1);
			print("All players are in game");				
		}

Networking Issue Client Side

$
0
0
What could be the reason for client's transform not updating in master server?

These 4 RPCs has been called in my script. But still if a player in client-side move, it is not updating in server but server-side movements are updating in client. Somebody please help!

               if (PlayersInGame==1)
		{
			PhotonView.RPC("RPC_SpawnPlayerCamera",PhotonTargets.MasterClient);
			PhotonView.RPC("RPC_SpawnPlayers",PhotonTargets.MasterClient,id1);			
			PhotonView.RPC("RPC_AssignPlayerButtons",PhotonTargets.MasterClient);									
		}
		else if (PlayersInGame==PhotonNetwork.playerList.Length)
		{	
			PhotonView.RPC("RPC_SpawnTargets",PhotonTargets.MasterClient,id2);
			PhotonView.RPC("RPC_SpawnTargetCamera",PhotonTargets.Others);
			PhotonView.RPC("RPC_SpawnTargets",PhotonTargets.Others,id2);					
			PhotonView.RPC("RPC_AssignTargetButtons",PhotonTargets.Others);		
			PhotonView.RPC("RPC_SpawnPlayers",PhotonTargets.Others,id1);
			print("All players are in game");				
		}

Has the free version of PUN been abandoned?

$
0
0
I really want to use PUN in my multiplayer game, but whenever I import PUN free into my Unity project, 2 things happen:
1)Unity throws up a dialog box saying that the APIs are outdated, and would I like to attempt to update them?
2) I get 33 compiler errors going: C:\Users\Public\Documents\Unity Projects\Project_Name\CSC: Warning CS1685: The predefined type 'System.Runtime.CompilerServices.ExtensionAttribute' is defined in multiple assemblies in the global alias; using definition from 'c:\Users\Public\Documents\Unity Projects\Project_Name\Assets\Photon Unity Networking\Editor\PhotonNetwork\Newtonsoft.Json.dll' (CS1685) (Assembly-CSharp) and when I ask it to take it take me to the line throwing up the error, it just says it can't find the file.
I know this is a problem with photon, as when I delete it from my project, the errors vanish.
So I'm just wondering, has the free version of PUN been abandoned while photon focuses on the paying customers, or have they just not noticed that PUN is broken?

Extra prefabs getting spawned

$
0
0
I use the following code to spawn Players. But when its called both master and client there are extra prefabs getting
spawned. Can someone help me?
Exactly 3 Target(clone) and Player(clone) are instantiated in the scene.
[PunRPC]
	public void RPC_SpawnTargets()
	{
		int i = 1;		
        TargetFormation=GameObject.Find("Target Formation").GetComponent<Transform>();
		foreach (Transform child in TargetFormation ) 
		{
			GameObject target = PhotonNetwork.Instantiate(Path.Combine("Prefabs","Target"),child.transform.position,Quaternion.identity,0) as GameObject;
			target.name = "Target ("+i+")";			
			target.transform.parent = child;
			print("Target Function called "+i+" times");			
			i++;
		}
		i = 0;		
	}

	[PunRPC]
	public void RPC_SpawnPlayers()
	{
		int i = 1;		
		PlayerFormation=GameObject.Find("Player Formation").GetComponent<Transform>();
		foreach (Transform child in PlayerFormation ) 
		{
			GameObject player =PhotonNetwork.Instantiate(Path.Combine("Prefabs","Player"),child.transform.position,Quaternion.identity,0) as GameObject;
			player.name = "Player ("+i+")";			
			player.transform.parent = child;		
			i++;
		}
		i=0;
	}
Viewing all 8947 articles
Browse latest View live


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