Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 frostymm · Jun 23, 2015 at 12:34 PM · errorobjectnetwork

Sending a System.object over RPC

So I've discovered that you can't cast something as an object and send it as a parameter through RPC. You can't do this because, your object will be instantly recasted as it's original type.

For instance if I make an RPC method that takes an "object" as it's parameter. If I cast a string as an object and call the RPC method using that as one of the arguments, it will throw an error saying something like "Photonview has no method "MethodName" that takes 1 argument(s): string"

Is there any way to bypass this and just send a generic object? It would make way more sense than me needing to make a new method for each type.

Note that I'm using Photon's PUN+, I don't know if this is still(was) the case with Unity's built-in RPC handler

Comment
Add comment · Show 5
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 Hellium · Jun 23, 2015 at 09:57 PM 0
Share

Why do you cast your string when calling the RPC since System.String directly inherits from System.object ? Though, you will have to cast your object into a string inside the body of your RPC.

avatar image frostymm · Jun 24, 2015 at 06:26 PM 0
Share

That was just an example. I'm trying to send hashtable values through RPC which are by default system.object's. The values aren't limited to any one type either. Some are strings, ints, floats, byte[]s and custom objects as well. It just seems silly to make a new function for each one of these types.

avatar image Hellium · Jun 24, 2015 at 06:37 PM 0
Share

Take a look at byte[] serialization with BinaryFormatter :

BinaryFormatter $$anonymous$$SDN :

https://msdn.microsoft.com/en-us/library/system.runtime.serialization.formatters.binary.binaryformatter.aspx

StackOverflow threads

http://stackoverflow.com/questions/15750154/serialize-an-object-in-c-sharp-and-get-byte-stream

http://stackoverflow.com/questions/7442164/c-sharp-and-net-how-to-serialize-a-structure-into-a-byte-array-using-binary

Then, make your RPC function take a byte array as parameter

avatar image Flightkick · Jun 24, 2015 at 07:12 PM 0
Share

You cannot directly send an Object, Prefab, GameObject etc. over RPC but you can serialize it, send the serialized data and deserialize it when received.

avatar image frostymm · Jun 24, 2015 at 07:12 PM 0
Share

I've thought about that, I was just hoping there was an easier way to force an RPC to take the object as a parameter without changing it. But if there's not, then I guess that's what I'll end up doing.

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Error after delete object! 0 Answers

How do I setup the Unity Network Connection Facilitator 0 Answers

Object reference not set to... 1 Answer

NullReferenceException 0 Answers

Using entities and jobs 1 Answer


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