Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by unity2020477 · Apr 03 at 08:21 AM · photonmultiplayer-networkingrpcpoker

RPC in unity with Photon not working

I am trying to code an online multiplayer poker game for me and my friends. I am just starting out and wanted to make a button, which, when pressed adds the value a ui- slider to the pot on every client. So I tried sending the pot-integer via RPC and it is just not working even after i have read through what feels like every question to that topic in every forum. thank you in advance for your help, I´ve added my script down below =)

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using Photon.Pun;
 using UnityEngine.UI;
 
 public class UIManagement : MonoBehaviourPunCallbacks
 {
     public Text pot;
     public int potInner = 0;
     public Slider slider;
     public int inputBet;
     private PhotonView PV;
 
     // Start is called before the first frame update
     void Start()
     {
         PV = GetComponent<PhotonView>();
         pot.text = "Pot: 0";
 
     }
 
     // Update is called once per frame
     void Update()
     {
         inputBet = Mathf.RoundToInt(slider.value);
 
     }
 
     public void HigherPot()
     {
 
             potInner = potInner + inputBet;
             pot.text = potInner.ToString();
 
             photonView.RPC("HigherOtherPot", RpcTarget.All, pot);
 
       
 
     }
 
     [PunRPC]
     public void HigherOtherPot(string potvalue)
     {
         Debug.Log("Finally");
         pot.text = potvalue;
 
     }
 }
 
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Captain_Pineapple · Apr 04 at 07:41 AM

Your code is almost correct. You should check what kind of variable you are currently trying to plug into your RPC.

your function definition states string and you give it a Text in the call.

best would be to change string to int as argument type as this is more friendly regarding message size. For things that get sent often consider to predict what range of numbers are enough for your case - do you need negative numbers? if not use an unsigned integer type. if 65535 numbers is enough use a short or ushort and so on. Bandwidth does not grow on trees.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by unity2020477 · Apr 04 at 04:55 PM

Thank you very much for answering that fast. It is really nice when as a beginner you needn't solve those issues on your own. Still after having fixed what you suggested, every time I run the Function "Higher Pot" it get the following error message:

 NullReferenceException: Object reference not set to an instance of an object
 UIManagement.HigherPot () (at Assets/Scripts/UIManagement.cs:36)
 UnityEngine.Events.InvokableCall.Invoke () (at /Users/bokken/buildslave/unity/build/Runtime/Export/UnityEvent/UnityEvent.cs:180)
 UnityEngine.Events.UnityEvent.Invoke () (at /Users/bokken/buildslave/unity/build/Runtime/Export/UnityEvent/UnityEvent/UnityEvent_0.cs:58)
 UnityEngine.UI.Button.Press () (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/Button.cs:70)
 UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/Button.cs:114)
 UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/ExecuteEvents.cs:57)
 UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/ExecuteEvents.cs:272)
 UnityEngine.EventSystems.EventSystem:Update() (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/EventSystem.cs:501)

I have assigned every variable in the inspector and just don't know how to continue. I hope these beginner questions are not bothering you, but trust me; I really tried to find the solution on my own.

Cheers

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Captain_Pineapple · Apr 05 at 05:30 AM 1
Share

No worries, everyone has to start somewhere. Nullreference exceptions are in general not allowed in here but either way:


If you understand the concept of the error message and what a Nullref is about then you wont have to ask about this again: A NullrefException says as you might already know that a variable is null.


Given this you always have to look through all value typed variables that you encounter in the line that your Exception points to:


UIManagement.HigherPot () (at Assets/Scripts/UIManagement.cs:36)

  photonView.RPC("HigherOtherPot", RpcTarget.All, pot);

In this case this would be pot and photonView. One of them MUST be null for this to happen. You can always check for this with a Debug.Log:

   Debug.Log($"Values of my variables:\nPV:{photonView} \npot:{pot}");

Now since pot is assigned in editor it probably is photonView which is null. This variable exists implicitly when deriving from MonoBehaviourPunCallbacks. The issue here is probably that you just don't have a PhotonView attached on the same GameObject.

avatar image unity2020477 Captain_Pineapple · Apr 05 at 01:40 PM 0
Share

Thanks I got it working now. And I apologize, didn't know null ref questions weren't allowed; Sorry XDXD

avatar image Captain_Pineapple unity2020477 · Apr 05 at 01:58 PM 1
Share

while one can argue if that is a good rule or not it is always a good idea to read the FAQ/Rules when you enter a new forum of any kind. This can be really really helpful to avoid common pitfalls like this topic.


Please also consider marking an answer as correct when it contains the solution to your question so that others know that the question was solved and/or have an easier time to find the correct solution in case there are multiple answers.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

145 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to share large image (Texture2d) across photon network? 0 Answers

Photon network doesn't call RPC/OnPhotonSerializeView 1 Answer

hi i need help with code 1 Answer

Do i need to turn on unity multiplayer in order to properly use Photon PUN 2? 0 Answers

How to set action upon collision between players?,How to set action upon player collision? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges