Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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
1
Question by Hellium · Jul 29, 2015 at 12:52 PM · networkspawnunity multiplayer

[UNet/HLAPI] Specify recipients of data sending / actions

Hello everyone,

I am changing a "network architecture" of my project from the old networking system to the new one using UNet / HLAPI. I am totally new to the new system.

By the way, I believe the new system is less flexible from the first one. You don't have much control as before ... Anyway ...

Context

I understood that the system is a server authoritative system, thus, all the data must be sent to the server before being sent to all the clients. And the fact that all the clients receive the data is exactly what I don't want. A similar problem I have is that spawning objects create the objects on all the clients.

Problem

I would like to prevent this last behaviour since my clients really don't care about the other clients, and I would like to save some bandwidth (it's very critical for the system I am making).

With the old system, I was using networkView groups from my clients as follow :

  void Awake()
  {
      // All network messages and RPC calls go through this group number
      networkView.group = 1;
 
      // Disable transmission of messages and RPC calls on the network group number 1.
      if( Network.isServer )
      {
          Network.SetSendingEnabled( 1, false );
      }
  }

But with the new system, I don't know if it's still possible.

But now, my first problem is to prevent the spawning of players on each clients. I could what I already made but if there is the new system, I guess it's possible with it too !


Alternative

If there is no way, I could just send an order to the clients to instantiate their players, and instantiate each players on the server too, but how can I make them communicate ? (Using NetworkViewId like before ?)

Comment
Add comment · Show 2
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 · Jul 29, 2015 at 12:54 PM 0
Share

I already tried to destroy the instantiated object if it's not a local player, but : it glitches + useless data sending + error raised by Unity.

 void Start ()
 {
     if ( !isLocalPlayer )
         Destroy( gameObject );
 }

$$anonymous$$issingReferenceException: The object of type 'NetworkIdentity' has been destroyed but you are still trying to access it.

EDIT : Overriding the NetworkBehaviour.OnStartLocalPlayer function solve this problem.

avatar image Hellium · Jul 29, 2015 at 02:11 PM 0
Share

It seems that a server can send a message to only client using

 NetworkServer.SendToClient<$$anonymous$$SG>(int,short,$$anonymous$$SG)

Doc : http://docs.unity3d.com/ScriptReference/Networking.NetworkServer.SendToClient.html

I will have to make some research to understand how can I use it for my problem ...

The documentation about UNet definitively lacks of examples.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by meat5000 · Jul 29, 2015 at 01:33 PM

I think this page is what you need

http://docs.unity3d.com/Manual/UNetVisibility.html

You should use ILSpy to bust open

C:\Program Files\Unity\Editor\Data\UnityExtensions\Unity\Networking\UnityEngine.Networking.dll

It is very very useful to see exactly how these methods are written.

Edit: This could be of interest

 // UnityEngine.Networking.NetworkServer
 internal static void HideForConnection(NetworkIdentity uv, NetworkConnection conn)
 {
     conn.Send(13, new ObjectDestroyMessage
     {
         netId = uv.netId
     });
 }

Which you could access via reflection, perhaps?

 public static void HideAnObject (NetworkIdentity myUV, NetworkConnection myConn)
     {
         Type netServType = Type.GetType ("UnityEngine.Networking.NetworkServer,UnityEngine");
 
         MethodInfo MyHideForConnection = netServType.GetMethod ("HideForConnection", BindingFlags.NonPublic | BindingFlags.Static);
         
         object[] myArgs = new object[] {myUV, myConn};
         
         MyHideForConnection.Invoke (null, myArgs);
     }

Here's some code that compiles but I've no idea if it'd work; never used Reflection.

Comment
Add comment · Show 4 · 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 Hellium · Jul 29, 2015 at 01:48 PM 0
Share

Aaaand, that's how you kill a fly with a bazooka ! x) I only need to instantiate empty points in each of my clients as input controllers to control server application. And I don't feel creating physic colliders, managing NetworkProximityChecker just to return false every time !

UNet is very, very game oriented, too much maybe...

Thanks for your answer @meat5000 , I think, I will have to keep it the old way !

avatar image meat5000 ♦ · Jul 29, 2015 at 05:50 PM 0
Share

@Hellium: Edited answer

avatar image Hellium · Jul 29, 2015 at 06:10 PM 0
Share

You should not spend so much time on my problem @meat5000 !

I must admit I have never used reflection though I understand a little bit its purpose. But I don't really understand what HideForConnection does ...

According to the doc, it sends a message ? But who is the recipient ? Where does the value '13' comes from ? ObjectDestroy$$anonymous$$essage is not documented (seems to be $$anonymous$$sgType.ObjectDestroy)

avatar image meat5000 ♦ · Jul 29, 2015 at 06:13 PM 1
Share

This is an internal $$anonymous$$ethod from Networking.dll

It appears that you specify a connection and a Network Identity and it hides the object.

Its worth the time spent as this is useful to a lot of people.

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

23 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

Related Questions

Network.Spawned objects won't show on new client 1 Answer

UNET NetworkServer.Spawn intermittently not called on clients 1 Answer

Network Animator not working 0 Answers

Is this the right setup for a multiplayer game? 0 Answers

playerControllerId higher than expected 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