Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[NO CCU LIMIT] Forge Networking now OPEN SOURCE

Discussion in 'Assets and Asset Store' started by Brent_Farris, Dec 22, 2014.

  1. Brent_Farris

    Brent_Farris

    Joined:
    Jul 13, 2012
    Posts:
    881
    Never fear, we are not going to put 100% focus on Bare Metal. The system is designed so that if we make one better it actually makes the other better at the same exact time :D

    You can send RPCs from the clients the way that you have always been doing and the server will distribute them. We will be adding in a plugin interface that will allow you to hook into the message receive so that you can control what happens with that message.

    We are still developing Bare Metal so when we get this part complete we will be sure to make tutorials on it! :D

    Yes, Bare Metal is for raw power in messages without any overhead of the engine. You would use it in the case that you don't need to process all the built in elements of Unity like Physics. For this you will want to use the unity server instance of Forge.

    Maybe not! Each game is unique and needs to be treated as such. If you get everything you need in the Forge Unity instance then that will be your best choice :)

    Yes, you can have both a Forge Unity instance and Bare Metal running on the same machine. You can assign a port for Bare Metal to connect to by just typing "start" and not "start -d".

    Also yes :D you can use Bare Metal as something like your lobby and a Forge Unity Instance as your main game, tough Bare Metal can be used as the main game as well if needed. I am hopeful that having the power of both and combining them can make very efficient games :D
     
  2. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    @GraphXCreations I think bare metal is a feature of Forge that extends it for use in games like mine that require only communication and no simulation. Though the Unity instance version is already very efficient, this just makes Forge as good as it can be for all developers.

    @ForgeTeam I really appreciate you guys taking the extra effort to accommodate games like mine. Many authors of networking solutions have considered it optional but you guys have put in just as much effort into this as you do to all pieces of Forge. Now, nobody can say Photon's more performance-friendly because it isn't!
     
  3. Cranick

    Cranick

    Joined:
    Nov 20, 2011
    Posts:
    310
    Thank you for taking a look at Forge! We hope that you will enjoy using it as much as we do. As Brent said, please send an email to support@beardedmangames.com and we will add you to our list!
     
  4. Cranick

    Cranick

    Joined:
    Nov 20, 2011
    Posts:
    310
    Why thank you from the Forge Team! We will always do our best to accommodate everyone including ourselves as this is the networking solution we always wanted for us and others. As Brent has said, we have done constant work of making sure that all necessary features are in and because of the way that Forge is designed, it is easy for us to implement features whereas other systems have to take more time to show any results.
     
  5. Brent_Farris

    Brent_Farris

    Joined:
    Jul 13, 2012
    Posts:
    881
    I would like to remedy my lack of information on this, I think I was in the heat of programming something when I replied to this. 15 bytes is the minimum header size for packets that are not using WriteRaw (as WriteRaw uses 2 byte headers). In most cases, since packets work with objects in the scene, the packet headers will be 32 bytes (of course WriteRaw is still a 2 byte header). We will work to bring this number down as much as possible though!
     
  6. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    32 is absolutely no problem, and since I communicate primarily through WriteRaw, I think this value might be less for my game.

    By the way, I'm a little embarrassed to ask this, but is it possible the id parameter of WriteRaw could be made a uint rather than a ushort? It'd be very specialized for my game but I have good reason to want this. For packing my variables into a byte array, 2 bytes of storage is simply not enough so I won't be able to use it effectively. 4 bytes, however, would suit mine and many other cases very well in effectively packing variables into a byte array.
     
  7. Brent_Farris

    Brent_Farris

    Joined:
    Jul 13, 2012
    Posts:
    881
    Awesome :). We will still continue to work on designs to bring this number down.

    I have a new design for WriteRaw. In this case the header will be either 1 byte, 3 bytes or 5 bytes. With this we will delegate what the id is, that way we are pulling raw power and flexibility :). This may sound confusing now due to lack of information or example, but on your end it will look like WriteRaw or WriteRaw16 or WriteRaw32 or WriteRawU16 or WriteRawU32. That way you can have a method for the different types of writes. We will handle all the delegation to end events magically in the back-end.
     
    jpthek9 likes this.
  8. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    Awesome! More than I could've asked for!
     
  9. Zaddo67

    Zaddo67

    Joined:
    Aug 14, 2012
    Posts:
    489
    Hidden in your last post was a little gem, Bluetooth support :) This is great news!!!
     
  10. Cranick

    Cranick

    Joined:
    Nov 20, 2011
    Posts:
    310
    This is something that I have been working on for our system as well as almost finishing up the downloading of our beta through our website using an access code given to the users by us. This will allow people to easily go to our website to get the latest version as well as be up to date with information.

    I hope with these changes we can help people have easier access to Forge and the future of it. We still have planned features that we cannot describe yet but Bluetooth is something that I was very fond of getting in for my personal games as well.

    Thanks
     
  11. Brent_Farris

    Brent_Farris

    Joined:
    Jul 13, 2012
    Posts:
    881
    Well that cat is out of the bag XD good thing we have tons more cats in this bag! :D
     
  12. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    I've been thinking that a WriteRaw without an id would be more useful than an additional WriteRaw32 to let developers implement their own id. If this is possible, can it happen?
     
    Last edited: Feb 2, 2015
  13. Brainswitch

    Brainswitch

    Joined:
    Apr 24, 2013
    Posts:
    270
    While initial (and quite limited) testing with an early beta wasn't very harmonious with our tests, the later/latest one has shown much improvement. We are planning on conducting some better/larger tests and then perhaps switch out our current networking for Forge.
    Great work so far, keep it up!
     
    Brent_Farris, Cranick and jpthek9 like this.
  14. Brent_Farris

    Brent_Farris

    Joined:
    Jul 13, 2012
    Posts:
    881
    Yes, I would be happy to switch WriteRaw to send only 1 byte header for internal uses and then allow the developer to deal with the rest of the payload themselves :)
     
  15. Brent_Farris

    Brent_Farris

    Joined:
    Jul 13, 2012
    Posts:
    881
    That's great news! We only hope to get better and better. Thank you for trying out our early Beta and sticking it out! I know it was a bit rough at the beginning, but it really helped us design a system that was extremely flexible for us to expand on. Once we got the design down, we tightened the belt on performance and bandwidth. Now we have a lean mean feature building machine. Of course there will always be work on performance and bandwidth and we will always audit our code for optimizations!

    Thank you again for sticking around to see how this system is turing out! We will always be available to hear/implement your feedback, bug fix reports and feature requests :D
     
  16. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    YES! A byte saved is a byte earned :D.
     
  17. Cranick

    Cranick

    Joined:
    Nov 20, 2011
    Posts:
    310
    Exactly :D you run that 1 byte say 1 billion times (not too much to ask) and you got yourself a gigabyte saved! :D
     
    Last edited: Feb 3, 2015
  18. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    Hi, I wrote up the structure of how I'm going to create a lockstep client-server RTS game with Forge here (sorry for another wall of text). It'd kind of a guide but mostly a way for me to organize the concept beyond an abstract idea in my head. I'll definitely be expanding on this, maybe create some video tutorials on how to implement it specifically with Forge. Hopefully, people will also help with the topic and flesh it out or optimize it with their suggestions. After I finish it, I'd like to tidy it up and release it as an extension for Forge. Are you guys okay with this?
     
  19. Brent_Farris

    Brent_Farris

    Joined:
    Jul 13, 2012
    Posts:
    881
    Awesome! This system sounds really exciting. Just because we love to support individual projects we would like to keep in communication with you about this project. If there is anything we can do to help the process of this system we would like to assist. Since this is an ambitious project we would like to keep in touch in order to iron out any bugs or inefficiencies that you have during the development of it.

    We are actually fans of RTS games ourselves! :D I am excited to see that Forge will have an opportunity to work with one of our own favorite game types :). I read your post and will be reviewing the link that you have provided to Gamasutra. Your layout is interesting, we will do our best to give input where we can to optimize it. I'm sure with good hard work you will be able to get it to a AAA quality level, then you will have the guys at Blizzard asking how you did it ;D.

    We are 100% excited to have developer driven extensions! You may have not noticed but we have developed a little Networking window for the system that we put in a while back (and haven't updated just yet). We will have space in here to show off peoples games and extensions :)
     
  20. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    Great! I'll do my best to whip out a prototype as soon as possible so I have something ya'll can help me with.

    On a sidenote, is the integrity of data sent reliable for WriteRaw? I was reading over ways to package data and some of them noted an extra part of verifying that all the data is the same when it's received.
     
  21. Brent_Farris

    Brent_Farris

    Joined:
    Jul 13, 2012
    Posts:
    881
    Right :). So WriteRaw is bare bones nothing, so it is a layer where you can design the packets in any way that you wish. For a packet you can do things like a "checksum" which is the process of adding up all the bytes in the packet and saving its resulting value as the validation. Then when the packet gets to the other side you can add up the bytes and make sure they match the validation.
     
  22. Brent_Farris

    Brent_Farris

    Joined:
    Jul 13, 2012
    Posts:
    881
    Hey guys, I'll be pushing out version 10 tonight with the new WriteRaw and a link to the website to try out the new Bare Metal Beta. Bare Metal currenlty doesn't have anything for sending messages through a plugin yet, but it has plugins for you to intercept messages and process them :)
     
  23. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    Oh, that sounds pretty convenient. I have to send data lengths to accommodate the compression of commands anyways so there won't be any additional data put in. I actually had nightmarish ideas about data sending like they would turn up as different values or something. That could be a scary story told to scare people off from every thinking of making a multiplayer game.
    I'm extremely excited about Bare Metal. I'm looking forward to putting the client-server lockstep concept to the test. I can already taste the sweet victory of seeing the first synchronized "Hello Lockstep" print. There's no immediate need for sending messages for me because I have a lot to do for hammering in the steps, metering, and decompression.
     
    Last edited: Feb 3, 2015
  24. Cranick

    Cranick

    Joined:
    Nov 20, 2011
    Posts:
    310
    Great news everyone! :D

    Everyone will now receive their re-usable beta access code to be able to download the latest build on our website. This is for easier access instead of going through your mail. We are still going to send out our update email to everyone so no worries on that.
     
    Neo-Gamefactory and jpthek9 like this.
  25. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    This sounds great and very professional. I'll reflect upon my beta access code with pride.
     
  26. Neo-Gamefactory

    Neo-Gamefactory

    Joined:
    Oct 18, 2012
    Posts:
    145
    Updates comes Daily, fast support and perfect NetworkSolution and it is BETA.. awesome :) good work!
     
  27. Brent_Farris

    Brent_Farris

    Joined:
    Jul 13, 2012
    Posts:
    881
    Thanks! :D Since we use this system ourselves we are constantly working on it! We can't wait to add in new features that can really boost the power of the system. We are very passionate about this system and hopefully it will help everyone who uses it to achieve their game designs :D

    We are actually about to send out a new beta, look for it in your inbox soon! :D
     
    Neo-Gamefactory likes this.
  28. Cranick

    Cranick

    Joined:
    Nov 20, 2011
    Posts:
    310
    Sorry guys for the delay, we are working out the new system for Downloading through our website and are running through some hoops :oops:, we hope to make the basketball shot tomorrow morning. Thanks all and keep your eye out for the beta email with access codes for our website tomorrow morning.
     
  29. RandAlThor

    RandAlThor

    Joined:
    Dec 2, 2007
    Posts:
    1,293
    Hi, do not read thrue the full thread, sorry.
    Will this become a product that we can buy in the asset store and if so how much will it cost then round about?
    I like the feature that i can send messages to just someone.
     
  30. Neo-Gamefactory

    Neo-Gamefactory

    Joined:
    Oct 18, 2012
    Posts:
    145

    Haha :D i just downloaded the Beta 9.2 :D You are freaky fast. I like this :)
     
  31. Brent_Farris

    Brent_Farris

    Joined:
    Jul 13, 2012
    Posts:
    881
    This will be a product that you can buy on the asset store. We are not 100% sure of the final price of the product, however we can say that even with all of the features and extensibility, we have no plans to break (will not be more than) $100 USD when we release. We will be reviewing the price point of the competition (under $100 USD) and will be making a fair and competitive price :)

    That being said, all of our Beta testers are getting a discount for their hard work, suggestions, bug reports, and feedback! So if you would like to be a part of the beta, just send me a message with your email or you can send an email to support@beardedmangames.com with the subject as "Forge Networking Beta"
     
    jpthek9 and Neo-Gamefactory like this.
  32. Neo-Gamefactory

    Neo-Gamefactory

    Joined:
    Oct 18, 2012
    Posts:
    145
    Good price for this :)
     
  33. Cranick

    Cranick

    Joined:
    Nov 20, 2011
    Posts:
    310
    Beta V10 has been released, everyone on the beta should have received their personal codes already, please follow the instructions in the email and if you have any problems feel free to contact us!
     
  34. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    Just got the new version! Bare Metal looks so sexy! A command that could be useful is 'pause' and a corresponding 'unpause' that would be similar to stop and start except it saves the data of the room and automatically starts with that data (port, max connections, etc.). Also, stopping and starting again causes the server to crash with the following shown on the console:

    Protocol type TCP/UDP (udp = 1, tcp = 2): 1
    The protocol type has been assigned to UDP
    Starting server on port 1 with 1 players using UDP
    System.Net.Sockets.SocketException: Only one usage of each socket address (proto
    col/network address/port) is normally permitted
    at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress
    socketAddress)
    at System.Net.Sockets.Socket.Bind(EndPoint localEP)
    at BeardedManStudios.Network.SocketPolicyServer.Start()

    And this in a debug log:

    System.InvalidOperationException was unhandled
    Message: An unhandled exception of type 'System.InvalidOperationException' occurred in System.dll
    Additional information: You must call the Bind method before performing this operation.

    Other than that, it works just as good as a Unity instance host.
     
    Last edited: Feb 3, 2015
  35. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,350
    Has anyone here used Bolt, and if so, how does this library compare?
     
  36. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    This is better than any library I've ever used. Firstly, it offers server logic in Unity instances as well as simple .net so it scales down to as little overhead as your project needs. Also, Forge gives developers great control over everything about the networking through events which really reminds me of DarkRift except it's continually expanded upon. Server plugins are very flexible and easy to write so you have a lot of control over your project. I haven't tried out Bolt, but I know that they won't have the same features planned for Forge like an integrated database (accounts, player currency) as well as a cloud. You can probably try out the Beta for Forge and see for yourself (just message the author). I'm not sure if Bolt has a demo but first-hand experience is always the best.
     
  37. Brent_Farris

    Brent_Farris

    Joined:
    Jul 13, 2012
    Posts:
    881
    Hi there! We actually have a lot of beta testers who came from Bolt and many other networking systems. We would love nothing more than for you to try out our system and give us a full critique on what you like and don't like compared to other systems! Maybe the other systems do things really well that you like that we can integrate into our system? We are very open and we are willing to update or add any features to our system to make it perfect for developers; because if it is perfect for you guys, then it will be perfect for us to use in our games as well! :D

    Our beta is free and on-demand, all we would need from you to get started is an email address. You can either message me with your email or send an email to support@beardedmangames.com with the subject "Forge Networking Beta"

    What kind of games/applications would you like to use with networking? I am always curious to find out the tastes of different developers.
     
    Last edited: Feb 4, 2015
    Neo-Gamefactory likes this.
  38. Brent_Farris

    Brent_Farris

    Joined:
    Jul 13, 2012
    Posts:
    881
    Thanks ;D, we are trying to make it as sexy as possible. Also, this suggestion sounds awesome! We will add it into the feature requests!

    Woops! That is my fault, silly code got left in there. I'll be sure to fix that asap! I have to teach tonight after work so hopefully I'll have enough time to get version 10.1 prepared and uploaded.
    EDIT: :D This is good to hear. There are some things it is lacking such as identifying objects that are on scene start but we plan to design some ways to get these features in.
     
    Last edited: Feb 4, 2015
  39. GraphXCreations

    GraphXCreations

    Joined:
    Jul 6, 2014
    Posts:
    121
    for real?

    the one reason i have not been a fan of non unity servers is because the lack of physycs/server side collisions which without that there is no real 100% authoritative server.

    if you can add physics or server side collision to the bare metal will be great, assuming better performance and less overhead than a unity server instance.


    also, is it possible for us to add our own server commands?

    and last, is the baremetal server multiplatform using mono?
     
  40. Brent_Farris

    Brent_Farris

    Joined:
    Jul 13, 2012
    Posts:
    881
    Sorry about the miss-communication. At the moment a headless instance of Unity will be the best choice for anything that will need physics. If we are to add Physics into Bare Metal it will be post release and after the system has all of the features we need (due to a headless Unity instance already providing this with good performance). The features I was referring to was mainly things like Bare Metal knowing of SimpleNetworkedMonoBehavior objects that are already in the scene at start.

    Yes, you can add your own server commands by implementing the interface as seen in the video I posted here. :)

    Technically Bare Metal is running in .NET (which means it can run under mono on Linux and Mac). We chose .NET to keep hyper compatibility with our current system as well as Unity and also because it has built in algorithms for things like dictionaries that out-perform very common or popular C++ libraries by a fractional margin. However we mainly chose .NET for hyper compatibility for Unity. :D
     
  41. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    @GrapXCreations I don't think Bare Metal is intended to simulate anything (that would require creating/integrating a physics library, a hierarchy system, and many more things Unity already has). It's still authoritative, but rather in the sense that it manages players and packet sends. For example, my game needs no simulation but definitely needs a central server to organize everyone and keep them in sync.
     
  42. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    I have a question about the concept of time over a network. For my lockstep system, I need clients to keep track of the server's step count (100ms interval time) almost perfectly. For the start of the game, I want clients and the server to synchronously start their step count clocks so they stay in sync for the rest of the game with a .5 margin of error. Is there a way to measure the time it takes for a packet to reach its destination? I can use this to calculate when to sync the step counts.
     
  43. Brent_Farris

    Brent_Farris

    Joined:
    Jul 13, 2012
    Posts:
    881
    What you can do to get the current round trip time is to send a WriteRaw with the average amount of dummy bytes and get the time it was sent in milliseconds and then on the read event for raw compare the time * 0.5. Either this or you can track the headers of the bytes you send and check the time it comes back from the server rather than doing a WriteRaw. If you track multiples of these time stamps you can calculate an average as well. We can actually add in a lastPing and a averagePing to the normal packets. However if you are using WriteRaw this won't be able to be tracked and saved on our end due to the 1 byte header.
     
  44. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    Thanks for the info! Not being able to use the built-in function is no problem. I will only need to check the ping for the first few seconds to sync the clocks of the server and client with efficient some packets.
     
    Last edited: Feb 4, 2015
  45. Zaddo67

    Zaddo67

    Joined:
    Aug 14, 2012
    Posts:
    489
    I am getting an error on WriteCustom when client writes to server. Server to client appears ok.....

    Here is the call Stack:

    KeyNotFoundException: The given key was not present in the dictionary.
    System.Collections.Generic.Dictionary`2[System.String,System.UInt32].get_Item (System.String key) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:150)
    BeardedManStudios.Network.NetworkingStream.PrepareFinal (BeardedManStudios.Network.NetWorker socket, IdentifierType identifierType, UInt64 behaviorNetworkId, BeardedManStudios.Network.BMSByte extra, NetworkReceivers receivers, Boolean bufferedRPC, System.String customidentifier)
    BeardedManStudios.Network.NetworkingStream.Prepare (BeardedManStudios.Network.NetWorker socket, IdentifierType identifierType, BeardedManStudios.Network.SimpleNetworkedMonoBehavior networkedBehavior, BeardedManStudios.Network.BMSByte extra, NetworkReceivers receivers, Boolean bufferedRPC, System.String customidentifier)
    BeardedManStudios.Network.Networking.WriteCustom (System.String id, BeardedManStudios.Network.NetWorker netWorker, BeardedManStudios.Network.BMSByte data, Boolean reliableUDP, NetworkReceivers recievers)
    ZoneOfFun.Network.ForgeNetwork.zofSendToServer (System.String socketName, System.String command, Int64 fromUser, ISFSObject data) (at Assets/Server/Networking/ForgeNetwork.cs:254)
    NetworkManager.Send (System.String command, ISFSObject data) (at Assets/VersionOne/Game/Scripts/NetworkManagement/NetworkManager.cs:307)
    NetworkManager.TimeSyncRequest () (at Assets/VersionOne/Game/Scripts/NetworkManagement/NetworkManager.cs:699)
    TimeManager.Update () (at Assets/VersionOne/Game/Scripts/NetworkManagement/TimeManager.cs:75)
     
  46. Brent_Farris

    Brent_Farris

    Joined:
    Jul 13, 2012
    Posts:
    881
    Ack! Thanks for the trace, I'll take a look at this. I may not have a solution for it until tomorrow evening (for me) though. Is this a consistent error or does it happen at seemingly random times?
     
  47. Zaddo67

    Zaddo67

    Joined:
    Aug 14, 2012
    Posts:
    489
    I can't get past it at the moment. It is happening all the time.

    I tried a few trouble shooting steps. Restart Unity, run client in editor then tried running server in editor, checked connection was active. Still consistently got this error.

    I just took a look at the WriteRaw method. I thought about changing over to this. However, this doesn't support AddCustomDataReadEvent, or messages directed to a specific user. So even though it is a bit more light weight, I like these features in the WriteCustom, so will stick with it.

    ps: THanks for looking into this :)
     
  48. Brent_Farris

    Brent_Farris

    Joined:
    Jul 13, 2012
    Posts:
    881
    I am unable to reproduce it yet. We did change all the strings being sent over the network to now be indexes, are you currently running version 10?

    Also does the Write Custom sample scene work for you? You can check by running an instance in the server, selecting the cube in the scene view and watching the inspector as you press spacebar on the other instance.
     
  49. Zaddo67

    Zaddo67

    Joined:
    Aug 14, 2012
    Posts:
    489
    I was using version 8.1 and got the error. Then tried version 10, same thing.
    (Edit: It might have been version 9.2 I was using. Not sure now that I have changed it, sorry.)

    I couldn't see how your write custom example scene connected to a server?
    So I made a minor change to the code so it connected to my server. I got the same error. I have copied the code and the call stack below.

    Note also, I am not using Good'Ol'Sockets at the moment, because all my development is just on PC.

    Code (csharp):
    1.  
    2. using UnityEngine;
    3.  
    4. using BeardedManStudios.Network;
    5.  
    6. public class ForgeExample_WriteCustom : MonoBehaviour
    7. {
    8.     public string id = "MyClassThing_01";
    9.  
    10.     public int num = 0;
    11.     public bool buul = false;
    12.     public float money = 3.1f;
    13.     public string first = "brent";
    14.     public double big = 0.0000004;
    15.     public Vector2 v2 = new Vector2(5, 13);
    16.     public Vector3 v3 = new Vector3(9, 133, 123);
    17.     public Vector4 v4 = new Vector4(1, 3, 34);
    18.  
    19.     private BMSByte cachedData = new BMSByte();
    20.     private NetWorker socket;
    21.     private bool bfirst = true;
    22.  
    23.     private void Setup()
    24.     {
    25.         //Networking.PrimarySocket.AddCustomDataReadEvent(id, ReadFromNetwork);
    26.     }
    27.  
    28.     private void Awake()
    29.     {
    30.         if (Networking.PrimarySocket == null)
    31.             Networking.connected += Setup;
    32.         else
    33.             Setup();
    34.  
    35.         socket = Networking.Connect("127.0.0.1", 15367, Networking.TransportationProtocolType.UDP, false);
    36.  
    37.     }
    38.  
    39.     private void Update()
    40.     {
    41.         if (socket.Connected && bfirst)
    42.         {
    43.             bfirst = false;
    44.             Networking.SetPrimarySocket(socket);
    45.             Debug.Log("coinnected");
    46.         }
    47.         if (Input.GetKeyDown(KeyCode.Space))
    48.         {
    49.             num = 9;
    50.             buul = true;
    51.             money = 100.53f;
    52.             first = "Farris";
    53.             big = 214324.3533;
    54.             v2 = Vector2.one * 5;
    55.             v3 = Vector3.one * 9;
    56.             v4 = Vector4.one * 2.31f;
    57.  
    58.             cachedData.Clone(Serialize());
    59.             Networking.WriteCustom(id, Networking.PrimarySocket, cachedData, true);
    60.             Debug.Log("WriteCustom");
    61.         }
    62.     }
    63.  
    64.     private BMSByte Serialize()
    65.     {
    66.         return ObjectMapper.MapBytes(cachedData, num, buul, money, first, big, v2, v3, v4);
    67.     }
    68.  
    69.     private void ReadFromNetwork(NetworkingPlayer sender, NetworkingStream stream)
    70.     {
    71.         Deserialize(stream);
    72.     }
    73.  
    74.     private void Deserialize(NetworkingStream stream)
    75.     {
    76.         num = ObjectMapper.Map<int>(stream);
    77.         buul = ObjectMapper.Map<bool>(stream);
    78.         money = ObjectMapper.Map<float>(stream);
    79.         first = ObjectMapper.Map<string>(stream);
    80.         big = ObjectMapper.Map<double>(stream);
    81.         v2 = ObjectMapper.Map<Vector2>(stream);
    82.         v3 = ObjectMapper.Map<Vector3>(stream);
    83.         v4 = ObjectMapper.Map<Vector4>(stream);
    84.     }
    85. }
    86.  
    KeyNotFoundException: The given key was not present in the dictionary.
    System.Collections.Generic.Dictionary`2[System.String,System.UInt32].get_Item (System.String key) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:150)
    BeardedManStudios.Network.NetworkingStream.PrepareFinal (BeardedManStudios.Network.NetWorker socket, IdentifierType identifierType, UInt64 behaviorNetworkId, BeardedManStudios.Network.BMSByte extra, NetworkReceivers receivers, Boolean bufferedRPC, System.String customidentifier)
    BeardedManStudios.Network.NetworkingStream.Prepare (BeardedManStudios.Network.NetWorker socket, IdentifierType identifierType, BeardedManStudios.Network.SimpleNetworkedMonoBehavior networkedBehavior, BeardedManStudios.Network.BMSByte extra, NetworkReceivers receivers, Boolean bufferedRPC, System.String customidentifier)
    BeardedManStudios.Network.Networking.WriteCustom (System.String id, BeardedManStudios.Network.NetWorker netWorker, BeardedManStudios.Network.BMSByte data, Boolean reliableUDP, NetworkReceivers recievers)
    ForgeExample_WriteCustom.Update () (at Assets/Bearded Man Studios Inc/Networking/Examples/Write Custom/Scripts/ForgeExample_WriteCustom.cs:58)
     
    Last edited: Feb 4, 2015
  50. Brent_Farris

    Brent_Farris

    Joined:
    Jul 13, 2012
    Posts:
    881
    No problem!

    So I did some searching using the code you pasted. I got the same exact error you did however I noticed that Networking.PrimarySocket was not being set. Here are the modifications I did in order to fix it:

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. using BeardedManStudios.Network;
    4.  
    5. public class ForgeExample_WriteCustom : MonoBehaviour
    6. {
    7.     public string id = "MyClassThing_01";
    8.  
    9.     public int num = 0;
    10.     public bool buul = false;
    11.     public float money = 3.1f;
    12.     public string first = "brent";
    13.     public double big = 0.0000004;
    14.     public Vector2 v2 = new Vector2(5, 13);
    15.     public Vector3 v3 = new Vector3(9, 133, 123);
    16.     public Vector4 v4 = new Vector4(1, 3, 34);
    17.  
    18.     private BMSByte cachedData = new BMSByte();
    19.     private NetWorker socket;
    20.  
    21.     private void Setup()
    22.     {
    23.         Debug.Log("Setting up Primary Socket");
    24.         Networking.SetPrimarySocket(socket);
    25.  
    26.         Debug.Log("Registering read callback event");
    27.         Networking.PrimarySocket.AddCustomDataReadEvent(id, ReadFromNetwork);
    28.         //socket.AddCustomDataReadEvent(id, ReadFromNetwork);
    29.     }
    30.  
    31.     private void Awake()
    32.     {
    33.         socket = Networking.Connect("127.0.0.1", 15937, Networking.TransportationProtocolType.UDP, false);
    34.  
    35.         if (socket.Connected)
    36.             Setup();
    37.         else
    38.             socket.connected += Setup;
    39.     }
    40.  
    41.     private void Update()
    42.     {
    43.         if (Input.GetKeyDown(KeyCode.Space))
    44.         {
    45.             num = 9;
    46.             buul = true;
    47.             money = 100.53f;
    48.             first = "Farris";
    49.             big = 214324.3533;
    50.             v2 = Vector2.one * 5;
    51.             v3 = Vector3.one * 9;
    52.             v4 = Vector4.one * 2.31f;
    53.  
    54.             cachedData.Clone(Serialize());
    55.             Networking.WriteCustom(id, socket /* Networking.PrimarySocket */, cachedData, true);
    56.             Debug.Log("WriteCustom");
    57.         }
    58.     }
    59.  
    60.     private BMSByte Serialize()
    61.     {
    62.         return ObjectMapper.MapBytes(cachedData, num, buul, money, first, big, v2, v3, v4);
    63.     }
    64.  
    65.     private void ReadFromNetwork(NetworkingPlayer sender, NetworkingStream stream)
    66.     {
    67.         Deserialize(stream);
    68.     }
    69.  
    70.     private void Deserialize(NetworkingStream stream)
    71.     {
    72.         num = ObjectMapper.Map<int>(stream);
    73.         buul = ObjectMapper.Map<bool>(stream);
    74.         money = ObjectMapper.Map<float>(stream);
    75.         first = ObjectMapper.Map<string>(stream);
    76.         big = ObjectMapper.Map<double>(stream);
    77.         v2 = ObjectMapper.Map<Vector2>(stream);
    78.         v3 = ObjectMapper.Map<Vector3>(stream);
    79.         v4 = ObjectMapper.Map<Vector4>(stream);
    80.     }
    81. }
    Note that I changed the port to go to my current running server.