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

Master client never calls any raised event

$
0
0
Hello guys,

i created a helper class which contains a dictionary full of codes and multicast-delegates for my events:
private static Dictionary<byte, EventDelegate> events = new Dictionary<byte, EventDelegate>();
If any event gets raised there is this one single method for executing the correct delegate:
private static void OnEvent(byte eventcode, object content, int senderid)
    {
        if(!events.ContainsKey(eventcode))
        {
            Debug.LogError("Tried to call unknown event with code: " + eventcode);
            return;
        }
        var dele = events[eventcode];
        if(dele != null)
        {
            PhotonPlayer sender = PhotonPlayer.Find(senderid);
            dele(content, sender);
        }
    }
The OnEvent-Method is registered using
PhotonNetwork.OnEventCall += OnEvent;
.
This gets called in OnJoinedRoom-Method. The connectionStateDetailed is always Joined at this moment.

By default i raise my events using

public static void RaiseEvent(byte eventCode, object arguments = null, bool reliable = true, bool all = true)
{
Debug.Log("Raising Event "+eventCode);
PhotonNetwork.OnEventCall(eventCode, arguments, PhotonNetwork.player.ID);

var options = RaiseEventOptions.Default;
if (all)
{
options.CachingOption = EventCaching.AddToRoomCacheGlobal;
options.Receivers = ReceiverGroup.All;
}
{
PhotonNetwork.RaiseEvent(eventCode, arguments, reliable, options);
}
}
In fact all this works absolutely fine as expected but only the master client recieves no single event. Even the simple expression
PhotonNetwork.OnEventCall(199, null, PhotonNetwork.player.ID)
does not have any effect. I tested this in Unity-Editor and as Standalone. Same results

I hope you guys have some ideas why the eventsystem works for everybody but not for the masterclient.
Thanks :)

manually force a photontransformview update

$
0
0
Is there a way to manually force an update on photontransformview when it is set to ViewSynchronization.UnreliableOnChange. I have objects that get assigned network views and transform views that are set to ViewSynchronization.UnreliableOnChange however they do not update to the position on the other clients until after they move a bit.

If i set them to ViewSynchronization.Unreliable then they update fine but ideally i dont want all the objects to be set to always sending updates when they are not moving or being interacted with (unless i have missread what unreliable means and it only updates when the object has changed position)

does anyone know a way i can leave it on ViewSynchronization.UnreliableOnChange but when setting up the object on the joining client call something to go "move this to the position last sent" or something like that. Im guessing this is not the case as there will not be the stream data during that frame to send get it, if my thinking here is correct anyone got an idea of how can go around this.

Thanks

Odd error, Failed to network-remove on player join

$
0
0
I am testing out my game by running two versions on the same machine and I get a weird error when the second client connects to the game. Here is the error:

Failed to 'network-remove' GameObject. Client is neither owner nor masterClient taking over for owner who left: View (0)37 on PickUpFullHelm (scene)

Now what is weird is that I get this error for all objects that have been spawned in, as well as a few objects that are not spawned. Everything is working an I have no errors with the actual game play, this just seems like an odd error to be thrown randomly. Any ideas on what is going on?

Random matchmaking is not working after setting user id in AuthValues.

$
0
0
Hi,

Random matchmaking is not working after setting user id in AuthValues. Players always join different rooms. I am using latest version of PUN+ (1.89). Match making works if i don't set AuthValues. I don't want to use authentication. I just want to set user id so that player can rejoin the game after disconnect. Below is the code


PhotonNetwork.AuthValues = new AuthenticationValues(userId);
PhotonNetwork.autoCleanUpPlayerObjects = true;
PhotonNetwork.ConnectUsingSettings("1.0");


Here is the code for creating room


RoomOptions options = new RoomOptions();
options.MaxPlayers = 4;
options.PlayerTtl = 60000;
options.EmptyRoomTtl = 60000;
options.PublishUserId = true;
TypedLobby lobby = new TypedLobby("TempLobby", LobbyType.Default);
PhotonNetwork.CreateRoom(null, options, null);


Code to search room


TypedLobby lobby = new TypedLobby("TempLobby", LobbyType.Default);
PhotonNetwork.JoinRandomRoom(null, MAX_PLAYERS, MatchmakingMode.FillRoom, null, null);

RPC on local vs remote - issue with serialisation

$
0
0
I have a class which only contains float/enum/bool fields. If I run one one machine (as masterclient) the RPC call that sends an instance of the class works fine. If I run on two machines, the remote client fails to send the RPC to the masterclient - "Exception: cannot serialize()".

Note that the "HitPoint" field was a Vector3, which I thought Photon would serialize? I split this into floats while trying to track down this error - but I should be able to send Vector3/enum/etc - is that correct?

How can I figure out which field is causing the failure (if that's what it is)? Also, when running on one machine, does photon still perform serialisation? Can't understand why it doesn't fail in all cases either.

Thanks!

---

public enum EFFECT_TYPE
{
GENERAL,
DAMAGE_DIRECT,
OTHER
}

[Serializable]
public class Damage {

public EFFECT_TYPE EffectType { get; set; }

public float InitialDamage { get; set; }
public float DamagePerSecond { get; set; }
public float DamageDurationSeconds { get; set; }

public float HitPointX { get; set; }
public float HitPointY { get; set; }
public float HitPointZ { get; set; }

public bool HitOtherPlayer { get; set; }

public SpellDamage()
{
}

public Damage(float initialDamage, float damagePerSecond, float damageDurationSeconds)
{
//just assigns data to fields above - nothing special
}
}


photonView.RPC("ReceiveEffectServer", PhotonTargets.MasterClient, damage);

[PunRPC]
public void ReceiveEffectServer(Damage damage)
{
...
}

Understanding Ownership

$
0
0
Great plugin! I have been able to prototype quickly with this and this solution appears to be ideal for my needs! Thanks much to the dev team!!! I have been cruising right along and ran into a snag and I can't figure out how best to deal with this.

Currently making a two person zombie game. I have both players instantiating and am using PhotonView to sync animations and transforms.

There are zombies (BRAINS!)

Zombies are in the game scene as objects (not instantiated) and are triggered two ways. One, they have a collider that is a trigger. If either player enters the trigger, the zombie (which also has a PhotonView component) moves and animates. Both players see it. So far so good.

The other way they are triggered is if they are shot.

To shoot I am using a raycast script on the gun. It sends damage data and the root of the gun (player) to the zombie script. On receiving this data the zombie script calls a remote procedural call that sets the zombies target to the game object and applies damage.

If either player enters the trigger zone of the zombie, it follows the player, all animations and transforms work as expected, both players can damage and kill the zombie and see animations. So far so good.

However, if the second player to join shoots the zombie, it sets this player as the appropriate target, but it will not move. It animates, but doesn't move. I think the other players PhotonView is controlling the zombies position, because if I uncheck the zombie's -PhotonView in the editor, it approaches player two as expected.

Couple of things where this might be getting tripped up. One, you can't pass GameObjects with [PunRPC] - so I am setting a temporary object in the zombie script that calls the RPC, then setting the target within the call.

This also might be a question of ownership, although I confess ownership confuses me a bit. I thought it was the role of the PhotonView to track the position and animations of objects and make sure that all clients would be updated. I have read through the docs, but I am not really getting when fixed, takeover and request would be helpful or necessary. if it is an ownership thing, why would the zombie work as expected if triggered, but not shot?

Here is the code where the zombie calls the RPC

public void Damage(float damageAmount, GameObject target)
{
tempObject = target;
pv.RPC("applyDamage", PhotonTargets.All, damageAmount);
}

applyDamage applies damage to the zombie and sets the target to tempObject;

Any insight is super helpful!

PUN keeps kicking me

$
0
0
Since I implemented some RPCs, PUN keeps kicking me..
This seems kinda obvious why. I am calling RPCs in the Update()'s of two objects.
Further, these are both sending arrays.
I am guessing this is just too much data? What is the limit to how many RPCs I can send, or is this not actually the issue?
Sorry for such a noob question..
Thanks!

Edit: I assuming it is kicking me, all of the instantiated objects just disappear, or could this be due to a bug in my code?

PhotonNetwork.Instantiate immediately gets destroyed

$
0
0
Hello,

I have completed my matchmaking lobby, it works very well. When i transition into my game room (master client calls PhotonNetwork.LoadLevel) I have issues spawning a player for each client. There is a photonView object with my script in the game room. On Start() it calls PhotonNetwork.instantiate. What ends up happening is that each client do in fact spawn the other clients players, but they instantly delete them with the error:

PUN-instantiated 'Prefab' got destroyed by engine. This is OK when loading levels. Otherwise use: PhotonNetwork.Destroy()

Ive also tried setting a 5 second delay to spawn to make sure all the players are in the room (Not a long term solution, just a test) Anyone ever have this problem?

Thanks,
Mitch

Client becomes Master when entering the room, only on iOS, Any ideas?

$
0
0
I'm using UFPS and the UFPS Multiplayer Kit, the problem I have is that when a client enters the room the game crashes for the master only, everything works as expected on the client (now new master), in other words it can only be one master and it will keep crashing if someone else enters the room, the problem it only appears on apple devices, I mean Mac (while testing in Unity) and iPhones or iPads, on Android everything works, as well as on PC. Here are the console errors:

NullReferenceException: Object reference not set to an instance of an object
vp_BodyAnimator.InitMaxSpeeds () (at Assets/UFPS/Base/Scripts/Gameplay/Player/vp_BodyAnimator.cs:823)
vp_BodyAnimator.Awake () (at Assets/UFPS/Base/Scripts/Gameplay/Player/vp_BodyAnimator.cs:310)
UnityEngine.Object:Instantiate(Object, Vector3, Quaternion)
vp_MPPlayerSpawner:InstantiatePlayerPrefab(PhotonPlayer, Hashtable, Int32, Int32, Int32, Int32, Int32) (at Assets/UFPS/Multiplayer/Scripts/Master/vp_MPPlayerSpawner.cs:401)
vp_MPPlayerSpawner:ReceiveInitialSpawnInfo(Int32, PhotonPlayer, Vector3, Quaternion, String, Int32, Int32, Int32, Int32, Int32, Int32, PhotonMessageInfo) (at Assets/UFPS/Multiplayer/Scripts/Master/vp_MPPlayerSpawner.cs:311)
System.Reflection.MethodBase:Invoke(Object, Object[])
NetworkingPeer:ExecuteRpc(Hashtable, Int32) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:3022)
NetworkingPeer:RPC(PhotonView, String, PhotonTargets, PhotonPlayer, Boolean, Object[]) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:3831)
PhotonNetwork:RPC(PhotonView, String, PhotonTargets, Boolean, Object[]) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonNetwork.cs:2941)
PhotonView:RPC(String, PhotonTargets, Object[]) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonView.cs:597)
vp_MPMaster:TransmitInitialSpawnInfo(PhotonPlayer, Int32, String, Int32, Int32, Int32, Int32, Int32, Int32) (at Assets/UFPS/Multiplayer/Scripts/Master/vp_MPMaster.cs:709)
vp_MPMaster:RequestInitialSpawnInfo(PhotonPlayer, Int32, String, Int32, Int32, Int32, Int32, Int32, Int32) (at Assets/UFPS/Multiplayer/Scripts/Master/vp_MPMaster.cs:657)
System.Reflection.MethodBase:Invoke(Object, Object[])
NetworkingPeer:ExecuteRpc(Hashtable, Int32) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:2999)
NetworkingPeer:OnEvent(EventData) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:2592)
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:153)

I'm not sure, but I think the problem starts with this function:
NetworkingPeer:ExecuteRpc

Any ideas why it doesn't work on iOS?

Thank you



Unity Photon Steam Friend Invite

$
0
0
Hello,

I am the founder of Partical Studios. Currently we're working on a new game. We're using Photon Networking for our new game. But i have a problem about Steam Invite.

I am creating a room in game then i want to invite my steam friends to the room. For this;

CSteamID invitedUserId = (CSteamID)0;
SteamFriends.ActivateGameOverlayInviteDialog(invitedUserId);

When he acceptes the invite, how can i bring him to my room? I want him to join my room directly.
Please help me, thanks!

The number of players in the room

$
0
0

hi,
Number of players is not correct when selecting a room.


for example: 10/16 Player
But when you enter the game there are a few people.

Photon Unity Networking v1.82

Medium-professional skilled PUN developer interested in joining our team?

referring to an object instantiated by the client

$
0
0
In my game the player that enters the server instantiated a boat, this boat and connected to him is his owner with the name he put at the beginning of the game, but when I want to teleport to my boat I go to the masterclient boat because the two boat they have the same name
script attach to the instantiated player to teleport to the boat
  • boat = GameObject.FindGameObjectWithTag ("boat");
    io.transform.position = new Vector3 (boat.position.x, boat.transform.position.y, boat.transform.position.z);

this is the script I wrote to get connected and instantiate


public class NetworkManager : Photon.MonoBehaviour {

public static NetworkManager netManager;
GameObject spawnpoint;
GameObject spawnpointboat;
public Text respawnText;
bool isDead = false;
float spawnDelay = 3f;
float timeNeeded;
public GameObject menuPanel;
public GameObject gamePanel;
public InputField nameField;

GameObject[] lootspawn;

void OnGUI()
{
GUI.Label (new Rect (10, 10, 100, 100), PhotonNetwork.connectionStateDetailed.ToString ());

}

// Use this for initialization
void Start () {
netManager = this;
timeNeeded = spawnDelay;

PhotonNetwork.autoJoinLobby = true;
lootspawn = GameObject.FindGameObjectsWithTag("coinspawn");

spawnpoint = GameObject.Find ("spawnpoint");
spawnpointboat = GameObject.Find ("spawnpointboat");
}

void Update()
{
if(isDead)
{
respawnText.text = "Respawn" + Mathf.Round(timeNeeded);
timeNeeded -= Time.deltaTime;
if(timeNeeded < 0.5f)
{

isDead = false;
timeNeeded = spawnDelay;
respawnText.gameObject.SetActive (false);
RespawnPlayer ();
}
}
}

void OnJoinedLobby()
{
PhotonNetwork.CreateRoom (null);
//PhotonNetwork.JoinRandomRoom();
}
//Ho fallito la funziona joinradomroom...ovvero no stanza trovata
void OnPhotonJoinRoomFailed()//onPhotonRandomJoinFailed()
{

}

void OnJoinedRoom()
{
// PhotonNetwork.Instantiate("caracter", spawnpoint.transform.position, spawnpoint.transform.rotation, 0);
PlayerIsDead();
menuPanel.SetActive (false);
gamePanel.SetActive (true);
if(PhotonNetwork.isMasterClient)
{

foreach(GameObject obj in lootspawn)
{

obj.GetComponent ().enabled = true;
}
}
// PhotonNetwork.Instantiate("boat",spawnpointboat.transform.position, spawnpointboat.transform.rotation, 0);
}
//Evocato e inizio gioco e dopo il tempo di spawn
void RespawnPlayer()

{
PhotonNetwork.Instantiate("caracter", spawnpoint.transform.position, spawnpoint.transform.rotation, 0);

PhotonNetwork.Instantiate("boat",spawnpointboat.transform.position, spawnpointboat.transform.rotation, 0);
}
//chiamat da player damage ogni volta che muore
public void PlayerIsDead()
{
isDead = true;
respawnText.gameObject.SetActive (true);

}
public void onConnectBtnPressed()
{
if(nameField.text != "")
{
PhotonNetwork.player.NickName = nameField.text;
if(!PhotonNetwork.connected)
{
PhotonNetwork.ConnectUsingSettings ("islandv0.1");
}
else
{
OnJoinedLobby();
}
}
}
}


Photon Animator mysteriously stops synchronizing parameters

$
0
0
I am using the photon animator to synchronize two parameters and it WAS working but all of a sudden it stopped synchronizing the parameters... I get no errors or warnings whatsoever, did I hit some cap or limitation here? The RPCs are working on the same object so I know the photonview and the object is correctly connected to the server... Any ideas?

Offline mode and RPCs - not entirely expected behaviour

$
0
0
According to the documentation, RPCs "work as expected" when offlineMode = true.

I have found that in my game, when in offlineMode, PhotonNetwork.room = null, which is intended behaviour, but this causes any RPCs to simply not execute, and also print the warning message "Cannot send RPCs in Lobby! RPC dropped."

This wouldn't be much of a problem (although the warning message spam is annoying), but there are a number of places in my code where i send an RPC to PhotonTargets.All (which of course includes the client who sends the RPC, i.e. the "client" playing in offlineMode) So, this method doesn't execute locally and the game breaks.

If this is the intended behaviour then fair enough, I can code around this, it's just I would have expected that an RPC in offlineMode with PhotonTargets.All as the recievers would get called locally.

NamePlates

$
0
0
When I Do NamePlates They Are Switched



Networking rigid body object doesn't work well

$
0
0
HI!

I'm making an multiplayer VR game with PUN, and I'm trying to create some objects that can be picked up and moved around by any players. However, the results are quite strange..

The positions of the same object are not consistent across clients. As well as this, the objects seem to kind of randomly float around the scene in a strange way..

Here are the settings I am using:


They are VRTK interactable objects. I have a script that I made that changes the photon view owner of the objects when they are grabbed, and this seems to work. So I'm not sure what else I need to change to get it to work?

Thanks!

How can I share if a gameobject is activated or not ?

$
0
0
I have a Little Problem :
I have different weapons and I switch them by activating or deactivating them. But Photon don't share if a gameobject is activaed or not. So how can I fix that ?

Unusual optimization question

$
0
0
I don't want to send the sender id when raising an event in photon because I don't need it. Is there a possibility to avoid that? Like changing a script by photon or changing the RaiseEventOptions?

Different send rate per photonview

$
0
0
Are we able to have different sendrate for different photonviews? I would want different objects to updated at different rates to optimize the data trasnfer.
Viewing all 8947 articles
Browse latest View live


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