Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Network Proximity Checker to determine visibility from multiple objects

Discussion in 'Connected Games' started by Vexorum, Aug 8, 2018.

  1. Vexorum

    Vexorum

    Joined:
    Jan 9, 2016
    Posts:
    5
    Context:
    I'm building a 2-to-8 player game. It's a top-down real-time strategy style game. The camera moves freely over the map and players click on their units to issue orders. I'm using Unity's Network Identity and Network Transform scripts to manage the distribution of GameObjects across clients and servers. It's going pretty well, but I hit a hurdle I bet others have already solved.

    Current situation:
    When a match starts, for each player is spawned a single "principle" player gameObject. In my case, this gameObject is invisible and does nothing except it spawns a number of different objects that the local player can control. I've set up a decently sized map and attached unity's Network Proximity Checker scripts to each of these gameObject prefabs. However, when determining which gameObjects to render, only gameObjects in the visibility range of the "principle" player gameObject are shown. Even though the other gameObjects have local client authority, their vision range is not considered when determining which gameObjects are visible.

    The question:
    My gameObjects represent units, moving across a map. Each unit has a vision range, set in its Network Proximity Checker script. How can I make these other units enable vision from their positions, instead of having vision only from the principle object?

    If you find my question unclear, please let me know and I shall attempt to clarify.

    Thanks for reading,
    -Vexorum
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    3,593
    So the network proximity feature isn't really designed to be used as RTS "fog of war". I'd either design my own proximity system, or not use it at all and implement fog of war on the clients probably by enabling/disabling renderers.

    Also understand that Unet's network proximity feature isn't deciding what objects to render, it is deciding what objects to sync at all to the individual clients. It is intended for reducing network traffic by not sending updates for objects that shouldn't be necessary to sync.
     
  3. Vexorum

    Vexorum

    Joined:
    Jan 9, 2016
    Posts:
    5
    Thank you, Joe-Censored.
    I pretty much came to the same conclusion yesterday. I'm rolling back to the work-in-progress of my own implementation. It doesn't use the proximity checker at all. Indeed it turns renderers on and off. I worry that as the number of units grows, the range-testing code might eat up too much CPU. I've tried to write it in an efficient way. But I suppose until this becomes a problem I'll stick to the first rule of optimization: Do not optimize.