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 Royall · Mar 20, 2014 at 03:11 PM · networkingsockets

Similar networking options in unity?

Hi there,

I have a question regarding Unity networking... At the moment I am trying to decide if it's best to move from GameMaker Studio to Unity for our 3d multiplayer RPG. We have put a lot of work in to our game already but we are kind of tired to work with a bad 3d engine like GameMaker and have to reinvent the wheel for some basic 3d visuals all the time...

The biggest problem we think we should have when porting from GameMaker to Unity is the networking aspect (a side from our little experience in Unityscripting). Our game at the moment works with simple buffers and sockets. Here is an example of our server code:

 while(socket_read_message(socket, global.buffer)) {
    a = readbyte(); //Message ID
    switch(a) {
       case 1:
             point_x = readshort();
             point_y = readshort();
             //Move player to location and send the new location to other clients...
             break;
       }
       case 2:
             //Other message...
       }
    }
 }

This is a snippet from the server message receiving part... A client sending a message will look like:

 clearbuffer()
 writebyte(1) //Message ID
 writeshort(point_x)
 writeshort(point_y)
 sendmessage(global.socket)

So after showing some of this GameMaker code... What would be the best approach to do this in Unity? We don't want auto syncing and stuff because it's a point and click game, so it only has to send a movement update when a player clicks and moves to a new location.

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

Answer by FLASHDENMARK · Mar 21, 2014 at 08:43 PM

You can create your own network back-end if you want. Or you may use existing ones. Unity provides one out of the box, but personally I would only use it until you become familiar with Unity and networking in general(from the sound of it you got networking covered).

You may also use Photon Unity Networking - a third party framework for Unity. There are others as well but Photon Unity Networking(PUN) is the easiest solution I have worked with. It is fast, reliable free, very easy to implement(works pretty much as an extension to Unity).

There are a few default ways of sending data either UDP-like and TCP-like. You can send data as easy as one line of code, supporting several data types and receivers:

 //Sends a simple message to all other clients
 photonView.RPC("Network_Message", PhotonTargets.Others, "I am sending others a message");

And receive network data easily:

 [RPC]
 void Network_Message (string msg){
     Debug.Log("Message received " + msg);
 }

Networking in Unity can be very simple and using PUN sending and receiving data is simple as the above examples.

I do not know GameMaker but I doubt when you have settled and "imported" your game into Unity you will feel any regrets. Whether it be networking or not Unity is simple. I will link to PUN so you can read about it and see how simple it is( you can also download a simple project from the Assets Store that very simply show different ways of networking).

PUN

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 Kiloblargh · Mar 21, 2014 at 08:51 PM

I am using a very similar approach in Unity; I have an indefinite number of controllable units that do not have their own Network Views. Instead, there is one game controller object with one network view per player, I'm keeping track of all moving units, turning their positions into an array of shorts, first serializing the length of the array, then using that to reconstruct the original array on the receiving side.

Read the documentation on OnSerializeNetworkView and BitStream; your existing code should directly port rather well. (Without actually doing anything with sockets.)

Also, you can send a byte[] as an RPC parameter; which is not in the documentation.

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

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

21 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

Related Questions

A node in a childnode? 1 Answer

yield return WWW; not returning 1 Answer

Unity Networking, connecting to sever problems :( 1 Answer

Unity array out of range exception, using photon unity network. 1 Answer

How to instatiate two players simultaneoulsy before loading level 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