• 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
Question by mischkom · Aug 18, 2021 at 04:57 AM · multiplayer-networkingrts

RTS like Frame on Minimap for user Camera Position with GL not rendering in Multiplayer (MLAPI)

Hello everybody,

I have been looking for anybody to encounter this problem for a while now and i am kinda stuck myself, probably because i am new to Unity and also Rendering with GL.

The Problem:

I am using MLAPI for Networking and have a Player Prefab which is getting spawned by my Networkmanager that has 2 Cameras. One MainCamera to view the Game and another one to view the Field from top down as a basic Minimap. It is probably not good practise to spawn in a lot of Cameras with each player that joins the game but I disable any Camera which is not on a local player and it worked fine for me so far.

Now I want to display a Frame which represents the borders of the MainCameras view on the Minimap using GL Vertices. The script on the Minimap camera (every Player Prefab has one) is the following:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using MLAPI;
 
 public class MiniMapScreenMarker : NetworkBehaviour
 {
     public Material material;
     public Camera playerCamera;
     public Camera minimapCamera;
     public List<Collider> floorColliders;
     public Vector3 topLeftPosition, topRightPosition, bottomLeftPosition, bottomRightPosition;
  
     public void Start() {
         foreach(GameObject gameObject in GameObject.FindGameObjectsWithTag("Floor"))
         {
             floorColliders.Add(gameObject.GetComponent<Collider>());
         }
     }
  
     public void Update() {
         if(IsLocalPlayer){
         Ray topLeftCorner = this.playerCamera.ScreenPointToRay(new Vector3(0f, 0f));
         Ray topRightCorner = this.playerCamera.ScreenPointToRay(new Vector3(Screen.width, 0f));
         Ray bottomLeftCorner = this.playerCamera.ScreenPointToRay(new Vector3(0, Screen.height));
         Ray bottomRightCorner = this.playerCamera.ScreenPointToRay(new Vector3(Screen.width, Screen.height));
  
         RaycastHit[] hits = new RaycastHit[4];
         foreach(Collider col in floorColliders)
         {
         if (col.Raycast(topLeftCorner, out hits[0], 200f)) {
             this.topLeftPosition = hits[0].point;
         }
         if (col.Raycast(topRightCorner, out hits[1], 200f)) {
             this.topRightPosition = hits[1].point;
         }
         if (col.Raycast(bottomLeftCorner, out hits[2], 200f)) {
             this.bottomLeftPosition = hits[2].point;
         }
         if (col.Raycast(bottomRightCorner, out hits[3], 200f)) {
             this.bottomRightPosition = hits[3].point;
         }
         }
  
         this.topLeftPosition = this.minimapCamera.WorldToViewportPoint(this.topLeftPosition);
         this.topRightPosition = this.minimapCamera.WorldToViewportPoint(this.topRightPosition);
         this.bottomLeftPosition = this.minimapCamera.WorldToViewportPoint(this.bottomLeftPosition);
         this.bottomRightPosition = this.minimapCamera.WorldToViewportPoint(this.bottomRightPosition);
  
         this.topLeftPosition.z = -1f;
         this.topRightPosition.z = -1f;
         this.bottomLeftPosition.z = -1f;
         this.bottomRightPosition.z = -1f;
         }
     }
  
     public void OnPostRender() {
         if(IsLocalPlayer){
            Debug.Log("Gl Render");
         GL.PushMatrix();
         material.SetPass(0);
         {
             GL.LoadOrtho();
             GL.Begin(GL.LINES);
             {
                 GL.Color(Color.blue);
 
                 GL.Vertex(this.topLeftPosition);
                 GL.Vertex(this.topRightPosition);
                 GL.Vertex(this.topRightPosition);
                 GL.Vertex(this.bottomRightPosition);
                 GL.Vertex(this.bottomRightPosition);
                 GL.Vertex(this.bottomLeftPosition);
                 GL.Vertex(this.bottomLeftPosition);
                 GL.Vertex(this.topLeftPosition);
             }
             GL.End();
         }
         GL.PopMatrix();
         }
     }
 
 }



When i test this being the only client (and host at the same time) it works wonderfully.

alt text

Now, if i spawn in a player myself, it still works fine. Whenever a client joins and is spawned in by the Networkmanager though, it is the only one rendering the frame on the Minimap. So basically the last one who joined can enjoy this feature, the rest has nothing. And as soon as the last joined client leaves, the second but last renders it again.

Now, if you are not familiar with OnPostRender(), the Docu says that the script has to be attached to the camera you want to render something on, which it is. Trying to debug this, i also tryed to make use of OnPostRenderCallback(Camera cam), which i basically copied from the Docu (OnPostRenderCallback Documentation). This registers any camera instead of only the one which the script is attached to. Interestingly, if I do not check for the camera of the Minimap here, I get of course these frames on the Minimap and the Player Camera. For any number of Clients. When i check for the Minimap camera by

if(cam == minimapCamera)

, it goes back to only rendering for the latest joined client.

I have cheked for the positions of the Gl.Vertices to not be 0 or all the same, but they are accurate and change their position as the player camera does. I do not know what to do anymore, it seems to me that it has to do with everybody seeing only the latest clients minimap camera view while rendering frames on their own or something like that but im kinda clueless about how I could deal with this, regarding that it reders prefectly, when i render those frames on both cameras for each client.

All help appreciated, have a nice day.

PS: sry for bad Uppercases, german habit.

minimap.png (151.4 kB)
Comment

People who like this

0 Show 0
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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

129 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 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 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 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 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 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

I'm finding closest with GameObject.FindGameObjectsWithTag("Enemy"). How can I use this code (or anything else) to find nearest enemy game object in multiplayer (unet)? 1 Answer

RTS networking basics 0 Answers

Drag to make box in RTS? 3 Answers

can someone help me with my hud? 1 Answer

Click and Drag RTS Mouse selecting script help. 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