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

Instantiate players in Photon. Photon Instantiate error: Index was outside the bounds of the array.

$
0
0
Hi! I´m a new using photon and unity, and I have a problem at the moment to instantiate the players in scene. I'm trying to get two players in different positions when loading the scene. But I get this error: IndexOutOfRangeException: Index was outside the bounds of the array.

what can be the problem? I understand the error which can come from the time of calling the array, but as I said before
I´m a new user in unity. I hope you can help me

Thanks
This is the code
public class Septup : MonoBehaviour
{
   
    public static Septup SP;
  
    public Transform[] posiciones;

    public void OnEnable()
    {
        if (Septup.SP == null)
        {

            Septup.SP = this;


        }
    }

}


public class PlayerM : MonoBehaviour
{

    public PhotonView PL;
 
    public int aparecer;
   
    void Start()
    {
         aparecer = Septup.SP.posiciones.Length;
        PL = GetComponent<PhotonView>();
             
        if (PL.IsMine)
        {
           
            jugador = PhotonNetwork.Instantiate("P1", Septup.SP.posiciones[aparecer].position, Septup.SP.posiciones[aparecer].rotation, 0);

        }
    }

}

Setting up Client-Side Prediction and having the MasterClient keep the authoritative game state.

$
0
0
Hi guys, I'm setting up a small multiplayer RTS game with PUN 2 in Unity. I know PUN uses a client-authoritative model, so I'm trying to use a 'dumb-client' model where every player in the room issues their commands to the master client, which sends the updated game-state back to the players. After that I will implement client-side prediction so that it seems instantaneous to the client while really it takes a little bit for the master client to get back to them, and as long as the client had the correct gamestate X ms ago (where X is the ping to the server) then it should be good, otherwise it will be corrected.

My question is regarding doing this with PUN 2. From what I've read, I will have to do this all manually with RaiseEvents. Does anybody here have experience setting stuff up like this in PUN? It seems like it's really going to be a pain. I'm pretty new to this so I feel it's going to be a STEEP learning curve. Any suggestions on how I can implement this so it's simple and effective is greatly appreciated, thanks.

AddForce not working - please help

$
0
0
here is the source code

gameObject.GetComponent<Rigidbody>().isKinematic = false;
gameObject.GetComponent<Rigidbody>().AddForce(gameObject.transform.right * speed );

but ball is not moving - what should i do ?

Setting custom player properties?

$
0
0
I'm trying to load in player weapons from a static scriptable object, and I'm doing this by first:
Adding a custom player property per weapon part
Then, getting the player's custom properties and loading that in

for some reason this doesn't work. The script that does this isn't disabled for other players, should I make it run only if isMine is true?

Here's what I've got so far:
void Start()
    {
        if(current == null)
        {
            current = this;
        }
        shooting = GetComponent<Shooting>();
        view = gameObject.GetPhotonView();
        LoadWeapon(WeaponManager.instance.ourWeapon);
    }
    /// <summary>
    /// Begins loading the weapon in from a data file
    /// </summary>
    public void LoadWeapon(WeaponData w)
    {
        ExitGames.Client.Photon.Hashtable parts = new ExitGames.Client.Photon.Hashtable();
        parts.Add("Body", WeaponManager.instance.ourWeapon.body);
        parts.Add("Barrel", WeaponManager.instance.ourWeapon.barrel);
        if (WeaponManager.instance.ourWeapon.underBarrel != null)
            parts.Add("UnderBarrel", WeaponManager.instance.ourWeapon.underBarrel);
        if (WeaponManager.instance.ourWeapon.overBarrel != null)
            parts.Add("OverBarrel", WeaponManager.instance.ourWeapon.overBarrel);
        PhotonNetwork.player.SetCustomProperties(parts);

        print(view.owner.NickName + "'s weapon body is: " + view.owner.CustomProperties["Body"].ToString());
    }

For some reason this doesn't work consistently every time, and sometimes only works for the person who joined first. Anyone know what's wrong?

RPCTarget basic concept

$
0
0
Hello,
So I was really confused about this really basic concept.

when I use a photonView.RPC("Fire" , RPCTarget.All )

Am I calling the "Fire" function
1) on my client (on this PC) and my client instance on every other pc
or
2) on my client (on this PC) and my client instance on every other PC + everybody else's instance(player)

I can't get the amount of Team Members (PhotonTeamsManager)

$
0
0
Hello everyone,
I use PhotonTeamsManager for my teams. And this system actually worked earlier. But now I get a "Null Reference" error when I try to get the amount of team members.
This is my little code where I get the amount of team members in a team (byte GetTeamMembersLength) and the function AssignTeams() is called in Awake() by the MasterClient:
https://pastebin.com/GFH5scFf

AnimatorControllerParameter - Problems after Upgrade Unity 2017 to 2018

$
0
0
Hello guys, I need some help. I was using Unity 2017 and after upgrade to the last version of 2018 this problem appears: AnimatorControllerParameter is an ambiguous reference between UnityEngine.AnimatorControllerParameter and UnityEditorInternal.AnimatorControllerParameter Thanks

Bug when using Photon + Unity XR Toolkit

$
0
0
When we destroy an object using PhotonNetwork.Destroy - it deactivates the object before destroying it. It causes the XRUIInputModule to fail on removing the interactor and disables the UI input for players.

go.SetActive(false); // PUN 2 disables objects before the return to the pool
in PhotonNetworkPart string 786 causes this issue.

Is there a reason why the object gets disabled before being destroyed?

Who is the one to blame here? Photon or Unity XR toolkit?

How to pick a specific user to start a 1v1 game. Dynamic AppID or lobby or other?

$
0
0
Background :
- My application has 2 types of user, Type1 and Type2. Although I do not think it matters much.

Goal :
- Once a Type1 user connects to the server
- The Type1 user should be able to see what other Type2 users are available.
- Then Type1 user can pick one Type2 user, and start a game (1v1)

Question :
- How should I approach this?

My ideas :
- Using different AppIDs for each user from the Photon dashboard and changing them in runtime in PhotonServerSettings. Is it possible to implement this idea? My project might need to go this way.
- Using Lobby and Room concept

Protection of photon AppID

$
0
0
I'm curious about AppID i'm using when compiling a project. Does it have some protection? Is it possible for someone who want to hack my game decompile a unity project and rebuild a working version? Or he will not be able to setup an appid again? Thank you!)

Pun tutorial bugs

$
0
0
I have completed the pun tutorial. However, there are some small bugs which I can't manage to figure out.

1. Local player is build version. Editor version is behind build version. Yet, the UI for editor version could be seen.
PXDkRwk.png

2. Ocassionally, when the 2nd player has left the game, the 1st player will not respawn at (0, 5, 0). This happens roughly 20% of the time.

3. When a new player joins the room, the original player will jump after a short run. This happens ocassionally as well.

Broken string serialization

$
0
0
In the Version 4.1.4.0 (27. April 2020 - rev5468)
A new bug was introduced when sending a string with characters bigger than 1 byte via RPC
I don't have access to the dll but probably you are sending the string length instead of the byte length for the serialization
ArgumentOutOfRangeException: ArgRange_StringRange
Parameter name: charCount
System.Text.UTF8Encoding.GetBytes (System.String s, Int32 charIndex, Int32 charCount, System.Byte[] bytes, Int32 byteIndex) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Text/UTF8Encoding.cs:388)
ExitGames.Client.Photon.Protocol16.SerializeString (ExitGames.Client.Photon.StreamBuffer stream, System.String value, Boolean setType)
ExitGames.Client.Photon.Protocol16.Serialize (


How do I access Photon Teams Manager?

$
0
0
Hello everyone,
I have a problem with the Photon Teams Manager in Unity. Since there is no actual documentation which helps me or I couldn't find it, but if it exists then it's hidden and hard to find. I don't know how to access this Photon Teams Manager script. I could manage my teams with Custom Properties but I think this already implemented function is better and more efficient. There is no method or namespace or even the class I can access. If I type in PhotonNetwork. and I want to write something with Team, there is no result. I have the namespaces using Photon.Pun; and using Photon.Realtime; but still nothing.
I hope someone could help me. Thank you very much!

[BUG REPORT] NullReferenceException in PhotonTeamsManager → OnPlayerLeftRoom(), OnPlayerEnteredRoom(

$
0
0
When player has no team, GetPhotonTeam() will return null.

So in OnPlayerLeftRoom and OnPlayerEnteredRoom functions. It should avoid null reference exception because it's going to break other OnPlayerLeftRoom/OnPlayerEnteredRoom functions which made on other components (Because this function being called in loop)

How to sync box trigger?

$
0
0
Hello i wanna sync my script because it's a trigger, how can i do this?
my script:
using UnityEngine;
public class coolhelicopter : MonoBehaviour {
    public Animator animator;
    void OnTriggerEnter(Collider other) {
        if (other.gameObject.CompareTag("Player")) {
            animator.SetTrigger("EYYY");
        }
    }
}

Error with Unity 2019.3.12

$
0
0
Hello,

I am developing an online game in Unity and have been following the Photon Pun tutorial provided.
https://doc.photonengine.com/en-us/pun/current/demos-and-tutorials/pun-basics-tutorial/intro

Initially I was using Unity version 2019.3.0 but I reached the section on Lobby UI and when I tried adding a function to OnValueChange I was not given the dynamic string option.
https://doc.photonengine.com/en-us/pun/current/demos-and-tutorials/pun-basics-tutorial/lobby-ui

So after some research I found that was a bug in Unity and was fixed in 2019.3.12, so I upgraded to the new version and now my Photon Library must not be working properly since in the code I get an error on the following line:

using Photon.Pun;

I tried re-importing Pun2 and starting a new project, but I still get the error with the newer version of Unity.

Any help would be much appreciated and if I should post some more info please let me know.

Thanks



Serialize a List of type Photon.Realtime.Player

$
0
0
Hello everyone,

I don't really understand how to serialize a List of type Photon.Realtime.Player. I want to pass some lists as parameters in my RPC function and one of these lists is a List of type Player. Now I get an Error and I know I have to serialize this. And I looked at some forum posts about serializing Vector2 and some other posts, but I still can't understand how to serialize a List<Player>.

Thank you already in advance.

PS: Is it bad (for the traffic or for the messages) to pass many parameters in my RPC function, especially Lists. Now I pass 10 parameters (float, float, float, bool, byte, byte, List<byte>, List<byte>, List<byte> and List<Player>). I mean, is it not recommended to pass 10 parameters in one RPC and 4 of them are lists or is it ok to do this?

System.Net.Sockets.SocketException (0x80004005): Invalid arguments (v2.17 )

$
0
0
Upgraded the SDK to the latest (v2.17 ) and when tapped on phone flight mode I get the following Exception instantly and disconnects with DisconnectCause.none
: Cannot send to: 92.223.82.24. Uptime: 25530 ms.   Local: 25.2.223.196:49380 Remote:  (not connected, not bound)
: System.Net.Sockets.SocketException (0x80004005): Invalid arguments
:   at System.Net.Sockets.Socket.Send (System.Byte[] buffer, System.Int32 offset, System.Int32 size, System.Net.Sockets.SocketFlags socketFlags) [0x00016] in <162d614634844458a5a341a34ee2c013>:0
:   at ExitGames.Client.Photon.SocketUdp.Send (System.Byte[] data, System.Int32 length) [0x00027] in <ecfe73d034e14d47aaf6dde8a90e224b>:0
: UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
: UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
: UnityEngine.Logger:Log(LogType, Object)
: UnityEngine.Debug:LogError(Object)
: Photon.Realtime.LoadBalancingClient:DebugReturn(DebugLevel, String) (at G:\IJS\SkipBoGit\skipbogame\SkipBoGame\Assets\Photon\PhotonRealtime\Code\LoadBalancingClient.cs:2297)
: ExitGames.Client.Photon.<>c__DisplayClass103_0:<EnqueueDebugReturn>b__0()
: ExitGames.Client.Photon.EnetPeer:Dispatc

So I reverted back the SDK to 2.13 and it works normally without exception and disconnects after a few seconds later. Which is the normal behaviour in my opinion.

Please correct me if I missed something to add with the new SDK. any new line of code has to be added to make it behave like the old version?

Sync SceneView with instantitated view

$
0
0
I would like to use a scene player object and sync it with avatar prefabs on the other clients.
My first approach was this:
  • Add all neccessary views to the player scene object and the avatar prefab
  • AllocateViewID for the player
  • Instantiate the Avatar via RPC and assign the allocated view id
This does not work though as the player gets a viewID on scene load and it cannot be changed afterwards,
which would lead to all players having the same viewID

Is there a better approach?
Or is it possible to prevent the players view from getting a viewID on scene load or change it afterwards?

Thanks,
Pascal

Stick with PUN or should I use Bolt?

$
0
0
Hello! I've been working on a Unity2D project that has some pretty fast game play. It's a sidescrolling platformer where you shoot at each other similar to Towerfall. I have everything working in PUN2 but I'm having an issue with lag.

I've made a lot of adjustments that have helped but there's still an issue with occasionally getting hit by a bullet when it looks like it should have missed.

After reading up on the differences between PUN and Bolt it seems like Bolt might be a better solution for a fast paced game like this. Am I correct in this assumption? Should I switch to Bolt or should I be able to make this work in PUN without any/much noticeable lag?
Viewing all 8947 articles
Browse latest View live


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