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

PhotonTransformView extrapolation and collision

$
0
0
When I put a PhotonTransformView on objects in my 2d game and activate 'extrapolation', I have problems where the objects will be placed outside of the world if I have a big lag spike.

The source of the problem _looks_ to be fairly clear. PhotonTransformViewPositionControl sets the destination point to be the sum of the last-known-network location plus the extrapolated position. When the amount of time passed is small, the object gets pushed into a wall, but collision pushes it right back out again. Once the time passed gets high enough, the object is placed on the other side of the obstacle.

I could fix this by writing my own extrapolation code to take collision into account, but I have to think I must be missing something here. As written, the extrapolation system is pretty much completely useless except in highly select circumstances like a space sim. In any other situation, this problem will result in objects interpenetrating objects, which is almost never right.

Am I missing something? Is there a different control or a different option I can use to fix this problem?

Thanks.



PUN Cloud Server + WebGL Build problem.

$
0
0
I'm having some issues connecting to the cloud server when running in WebGL build. Works just fine with standalone just not sure why it will not connect at all after i build it. I have been looking around , but i have not found much help with the cloud servers.

Any help will be much appreciated.

(I have also tried it on my website still the same issue as running it from my local machine)

OnPhotonSerializeView on a non-active gameObject

$
0
0
I wrote an OnPhotonSerializeView function to sync my information of a gameObject and ONLY the MasterClient was able to write to others

So this is the process of my code:
1) The gameObject was setActive to false locally by all the players, the gameObject syncs and log nothing
2) MasterClient gameObject SetActive to true, it starts to spam the Debug.Log("Sending") to my console
3) Other Player's gameObject sync and activate their gameObject (*!*)
4) After a few interaction, the MasterClient gameObject is SetActive to false again
5) But since the MasterClient has disable the gameObject, OnPhotonSerializeView is not spamming Debug.Log("Sending")
6) Other Player's gameObject are not SetActive to false

My Question is : How does the inactive gameObject on other player's able to sync the active state of the masterClient gameObject ? ( Which is Part 3 in the process )

Anyone have similar issues ? I like to understand why, tried to narrow down the issue but still lack of understanding the mechanism
	
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if( stream.isWriting && PhotonNetwork.isMasterClient )
{
stream.SendNext( gameObject.activeSelf );
stream.SendNext( status.text );
foreach( GameObject item in items )
{
stream.SendNext(item.activeSelf);
}
Debug.Log("Sending");
}
else
{
Debug.Log("Receiving");
gameObject.SetActive((bool)stream.ReceiveNext());
status.text = (string) stream.ReceiveNext();
foreach( GameObject item in items )
{
item.SetActive( (bool)stream.ReceiveNext());;
}
}
}

Room Options not Working with Unity 5.3.0 using PUN v1.24

$
0
0
Here is my piece of Code:
using UnityEngine;
using System.Collections;

public class NetworkManager : MonoBehaviour {
const string VERSION = "v0.0.1";
public string roomName = "VVR";
void Start () {
PhotonNetwork.ConnectUsingSettings (VERSION);
}
void OnJoinedLobby(){
RoomOptions roomOptions = new RoomOptions() { isVisible = false, maxPlayers = 4 };
PhotonNetwork.JoinOrCreateRoom(nameEveryFriendKnows, roomOptions, TypedLobby.Default);
}

}
it gives an error on RoomOpptions.
error CS0246: The type or namespace name `RoomOptions' could not be found. Are you missing a using directive or an assembly reference?
Please guide me.That will be great Favor.

How is RPC processed in the target ?

$
0
0
I have been using RPCs to process my players decision, so basically during an auction in the game, players will try to bid the price, which causes RPCs to send over the network to the Master Client ( I understand the Master Client can execute locally and resulting a faster bidding action ).

My question is, if multiple RPCs are called to the Master Client in a very close timing, are they process in a single thread manner ? or they are processed parallel ?

Though i saw threads in unity specifying unity is single threaded, i am not sure how PUN is design and embedded

Room name length and character limits?

$
0
0
Is there a max room name length and are there any not allowed characters? (Symbols etc) can it handle foreign character sets?

Character View Sync

$
0
0
Im developing a 2d sprite based multiplayer rpg. So after a while of research and little to no help from the community (cough) I have figured out (in my own way) how to sync the view of a character for my system at least. I wanted some insight because I feel the way im doing it isn't as efficient as it could be. If someone could tell me if there's a better way to do this that'd be greatly appreciated.

[PunRPC]
void UpdateInfo(PhotonMessageInfo info)
{
Debug.Log (info.sender.name + " sent this RPC.");

SkinController[] colls = GetComponentsInChildren ();

foreach (SkinController controller in colls)
{
foreach (SpriteCollection spriteColl in controller.skins)
{
object gender;
if (info.sender.customProperties.TryGetValue("Gender", out gender))
{
if ((int)gender == Helper.Constants.Male)
{
spriteColl.sprites = Resources.LoadAll (Helper.Constants.MaleFolder + controller.sprite_type + "/" + spriteColl.sheet.name);
}
else
{
spriteColl.sprites = Resources.LoadAll (Helper.Constants.FemaleFolder + controller.sprite_type + "/" + spriteColl.sheet.name);
}
Debug.Log (info.sender.name + " : " + (int)gender);
}
}
}

// If i sent this RPC, assign the equipment locally
if (info.sender.isLocal)
{
foreach (int equip_id in Session.CharacterData.CharacterEquipment)
{
Debug.Log (equip_id);
if (equip_id != 0)
{
GetComponent ().SetEquipment (EquipmentIndex.GetEquipmentById (equip_id));
}
}
}
else
{
object skin, hair, shirt, pants, shoes;
if (info.sender.customProperties.TryGetValue ("SkinId", out skin)
&& info.sender.customProperties.TryGetValue ("HairId", out hair)
&& info.sender.customProperties.TryGetValue ("ShirtId", out shirt)
&& info.sender.customProperties.TryGetValue ("PantsId", out pants)
&& info.sender.customProperties.TryGetValue ("ShoesId", out shoes))
{
GetComponent ().SetEquipment (EquipmentIndex.GetEquipmentById ((int)skin));
GetComponent ().SetEquipment (EquipmentIndex.GetEquipmentById ((int)hair));
GetComponent ().SetEquipment (EquipmentIndex.GetEquipmentById ((int)shirt));
GetComponent ().SetEquipment (EquipmentIndex.GetEquipmentById ((int)pants));
GetComponent ().SetEquipment (EquipmentIndex.GetEquipmentById ((int)shoes));
}
}
}


So basically what im doing here is first setting the characters gender, then the actual look of the character. The reason why i think this could be better is because i've mixed RPC's with custom properties which could be bad practice? I wasn't able to figure out another way to obtain the other characters equipment id's without trygetvalue'ing them from the custom props. Please any insight is appreciated or any advice.

Thanks,
Dev.

Photon Handler.Update framerate

$
0
0
Hi! I noticed that when I use PhotonNetwork.ConnectUsingSettings or createRoom the game is lowering the FPS for abount 2 seconds.
Using the profiler I found it was because of PhotonHandler update (deep profiler shows that the most of the CPU usage is generated via some calls to photon dlls from PhotonHandler update).

Is there any way that I can place this updates inside a thread only in that cases to avoid this decrease of the FPS?
Thanks

Add more manage features in a web panel, please! [three ideas inside]

$
0
0
1. Close all connections
If the bad guy get my AppID and create hundreds of connections, what can I do? - Nothing! Or if I want to update the game? You may have to reset all connections, if the update makes critical changes. Please allow to close all connections from a web panel.

2. Disable Multi-join for authorized players (then anonymous clients disabled)
The problem is that player from a single account can create hundreds of connections. What's the point? This is normally only for tests.

I propose to do so:
- User with a UserId (12344, for example) connect to Lobby
- Check if a user with a UserId (12344, for example) already exists in Lobby or in Game Servers, then server close all old connections in Lobby/Game Servers.
- Profit!

This is a logical behavior. If it is a game in Facebook, then I would not want the player to open the game in multiple tabs or via one account to play a few players.

3. Global cloud events
I would like to be able to send commands from a web panel for online players. Command consists of name (string) and optional parameters. In the code, it would look like this:
private void OnPhotonWebEvent(string name, Dictionary<string, object> parameters)
{
switch (name)
{
case "user_banned";
if (Social.User.ID == parameters["id"])
{
PhotonNetwork.LeaveRoom();
GameScreen.DisplayBannedWindow();
}
break;
case "global_message":
Chat.AddServerMessage(parameters["message"]);
break;
}
}

FindFrineds In Room

$
0
0
Can I use FindFriends() While i'm inside a room or it only works when i'm in the lobby??

and can i send a msg to my friends while i'm in the lobby.

what i'm trying to do is send an invitation to my online friends to start a game.

what is the best way to achieve that in ur opinion

thx in advance

MissingReferenceException: The object of type 'PhotonView' has been destroyed but you are still tryi

$
0
0
Hi,
We are using PUN+ 1.73. We have set autoCleanUpPlayerObjects to true. This exception happens very rarely when more than one player disconnects simultaneously. Because of this exception we see game objects of disconnected players in game.

Did this happen to anyone? What are the possible scenarios where it can happen. We are not destroying anything from our code.

MissingReferenceException: The object of type 'PhotonView' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
NetworkingPeer.DestroyPlayerObjects (Int32 playerId, Boolean localOnly) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:2969)
NetworkingPeer.HandleEventLeave (Int32 actorID, ExitGames.Client.Photon.EventData evLeave) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1205)
NetworkingPeer.OnEvent (ExitGames.Client.Photon.EventData photonEvent) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:2222)
ExitGames.Client.Photon.PeerBase.DeserializeMessageAndCallback (System.Byte[] inBuff)
ExitGames.Client.Photon.EnetPeer.DispatchIncomingCommands ()
ExitGames.Client.Photon.PhotonPeer.DispatchIncomingCommands ()
PhotonHandler.Update () (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:125)

Unparent an object while PhotonNetwork.connectionState == ConnectionState.Disconnecting

$
0
0
I have a player character who sits on a block. When the player character is sitting on a block he is the parent of the block. This is so that when I move the player character the block follows him exactly. When I disconnect from the game the player character (not scripted disconnect, but forced close of the game window), I need the block to stay on the game. As the block is a child of the player character it is being destroyed along with the player character. I have tried to unchild the block when the player character disconnects using



if (PhotonNetwork.connectionState == ConnectionState.Disconnecting) {

GetComponentInChildren<CheckForPassenger> ().DitchParentonDisconnect ();

PhotonNetwork.Destroy (gameObject);


}

but this is not working as I expected it to.

The block is originally a part of the scene and has a photonview. I do not instantiate the block. It is already part of the scene.

The block is still destroyed with the character. Any advice would be great ;)

Too many photonViews is bad. So how do you do it?

$
0
0
I am running into a problem where it is throwing an error saying I have too many scene objects.

Then I see threads saying too many photoviews are bad..

So how do I do this?

My game has a lot of enemies, lets say 100 on the map. That is 100 photonViews, it needs it because it updates position, hp, etc.

It also has resource nodes, which also has hp and I am photon instantiating them so it also must have a photonView. This is around 500 on the map.

If I dont use photonViews for these, how do I update their position, hp?
If I use RPC calls and add/remove a local copy, that means I have to keep track of every single instance and update accordingly which doesn't seem very effective.

What is the correct way of doing this?

Can I just increase the photonView limit?

Websockets + WebGL throwing exception, Unity 5.4 doesn't allow AddComponent(MonoBehaviour)!

$
0
0
EDIT: It looks like Unity 5.4 simply doesn't allow attached MonoBehaviour with AddComponent(). Any help would be appreciated, I literally can't connect until this is resolved :(

When connecting to PUN in Unity 5.4, it's throwing two (related) exceptions:

1) "AddComponent with MonoBehavior is not allowed." It references line 79 of SocketWebTcp.cs which does precisely what it says is not allowed (it's trying to add monobehaviour with addcomponent).
2) This then causes a null reference, not shocking where it didn't allow mb to be added, at line 84 of SocketWebTcp.cs where it attempts to do this: this.sock = new WebSocket(new Uri(ServerAddress));

PUN not removing disconnected players

$
0
0
Are there any known issues with photon not cleaning up players when a player disconnects? I'm running latest version as of 7-25-16 from unity asset store. I searched the forums and couldn't come up with anything.

Basically what is happening is I have a scene that players auto join a random room or create a room.

If one player leaves, then the disconnected players game object (a ship in this case) is controlled by the remaining player. So the only player in the room is controlling 2 ships at this point. If I rejoin with another game then there are 3 ships. Two being controlled by one player and the third by the last joined.

I looked into the clean cache options on room create as well as the auto clean player objects book set to true. Still same results. Any help would be appreciated. Thanks.

Problem with player left due to No internet connection

$
0
0
I have this simple question.
I am creating a game with capture the flag mode. Everything works fine but there is a situation. What will happen when one of my player has taken the enemy flag and suddenly disvonnects from photon. Right now if he got disconnected the falg is gone with him. Please tell me a way to detect his absence and if he is carring a flag,return the flag or put flag the last place he was.
I will be very thankful.
Thanks

PUN for online, UNET for LAN

$
0
0
Anyone doing that setup for their games?

How do you find maintaining the 2 setups?

Best way to detect user disconnects

$
0
0
Hi,

we are working on PVP game on iOS. User can turn off his wifi. Problem is that it took almost 10 seconds for client to realize that it was disconnected and getting OnConnectionFailed: TimeoutDisconnect.

We are using those values to set up photon:

PhotonNetwork.networkingPeer.DisconnectTimeout = 5000;
PhotonNetwork.networkingPeer.SentCountAllowance = 9;
PhotonNetwork.networkingPeer.MaximumTransferUnit = 1500;
Immediately after turning off wifi I get this error:

Cannot send to: 159.8.0.205. An invalid argument was supplied.

UnityEngine.Debug:LogError(Object)
NetworkingPeer:DebugReturn(DebugLevel, String) (at Assets/Plugins/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1444)
ExitGames.Client.Photon.<>c__DisplayClass138_0:<EnqueueDebugReturn>b__0()
ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands()
ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands()
PhotonHandler:Update() (at Assets/Plugins/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:125)
Could it be somehow used to detect disconnect faster ?

I know I can use unity to detect if device is not connected to any network and disable any player interaction, but is there any better way to do this ?

Have an RPC wait?

$
0
0
In my scene I have some items that a player can pickup. When a new player joins those items are visible to them and the RPC to have them disabled happens before the item is created so I get a "PhotonView doesn't exist" error. Is there a way to have an RPC wait until the level is loaded before calling it, it looks like right now the RPC is called as soon as the player joins the lobby, but I want to have it load after PhotonNetwork.LoadLevel.

Cheers,
Ben

How to synchronize a rigidbody's position that will change owners often

$
0
0
I'm working on a first-person game where players can pickup and throw weapons. Each weapon has a photon view set to takeover, when the weapon is picked up by a player the weapon transfers the ownership of it's photon view to the respective photon player. What I'm trying to figure out is how to synchronize the weapon's position and rotation after a player has thrown it. Not only does the weapon's position need to be synchronized after it is thrown, but when any other player interacts with the weapon's rigidbody after it has been thrown (hits it, pushes it, etc.).

My original thought was that the last player who used the weapon would be in charge of calculating the weapon's physics, the rigidbody would be turned off on all other clients and it's movement would be replicated. But I'm not sure how I would handle the instance where another player tries to interact with the weapon's rigidbody.

This is not critical to the gameplay, so long as it "looks" synchronized and the weapon ends up in the same position on all clients once it has stopped moving, that would be more than enough.

Any help would be great.
Viewing all 8947 articles
Browse latest View live