Quantcast
Channel: Latest Questions by Spikeh
Viewing all articles
Browse latest Browse all 16

Procedurally generated uGUI elements render under world space objects

$
0
0
Got to the point where I'm banging my head against a wall now, so here goes! I have a uGUI canvas prefab with a non-trivial hierarchy: ![alt text][1] HackingUI_DeviceCanvas is the object in question. This canvas is loaded (as a prefab) using Instantiate() when the game starts, and I assign the relevant camera to it: private void CreateHackingDeviceDetailsUI(Camera cam) { // Create the UI overlay var hackingUIDeviceDetailsGO = Instantiate(HackingUIDeviceDetailsCanvasPrefab) as GameObject; if (hackingUIDeviceDetailsGO == null) { Debug.LogError("Unable to instantiate the hacking UI device details UI canvas"); return; } _hackingUIDeviceDetailsCanvas = hackingUIDeviceDetailsGO.GetComponent(); _hackingUIDeviceDetailsCanvas.worldCamera = cam; // Get all UI panel references _pnlCamera = GetChildGameObjectByName(_hackingUIDeviceDetailsCanvas.gameObject, "pnlCameraView"); _pnlRelayRules = GetChildGameObjectByName(_hackingUIDeviceDetailsCanvas.gameObject, "pnlRelayRules"); _pnlRelayRuleList = _pnlRelayRules.transform.Find("pnlRuleList").Find("pnlContent") as RectTransform; var deviceNamePanel = GetChildGameObjectByName(_hackingUIDeviceDetailsCanvas.gameObject, "pnlDeviceName"); if (deviceNamePanel != null) { _txtDeviceName = deviceNamePanel.GetComponentInChildren(); } var deviceStatePanel = GetChildGameObjectByName(_hackingUIDeviceDetailsCanvas.gameObject, "pnlDeviceState"); if (deviceStatePanel != null) { _txtDeviceState = deviceStatePanel.GetComponentInChildren(); } var deviceSecurityRatingPanel = GetChildGameObjectByName(_hackingUIDeviceDetailsCanvas.gameObject, "pnlSecurityRating"); if (deviceSecurityRatingPanel != null) { _txtDeviceSecurityRating = deviceSecurityRatingPanel.transform.Find("txtSecurityRating").GetComponent(); } // Disable the canvas / some panels by default _hackingUIDeviceDetailsCanvas.enabled = false; ActivateCameraPanel(false); _pnlRelayRules.SetActive(false); } This all works beautifully. However, when I try to add another prefab (instantiated in the same way), and child it to the _pnlRelayRules object above, it renders behind the camera's world space objects. Code (the prefab is instantiated in the for loop): protected void OnMessage_ShowRelayRules(CyberspaceUIDevice device) { var rules = device.RelatedNetworkDevice.NetworkDeviceRelayRules; if (rules.Length <= 0) { return; } foreach (var rule in rules) { var ruleListItem = Instantiate(HackingUIRelayRuleListItemPrefab) as GameObject; ruleListItem.transform.localScale = Vector3.one; ruleListItem.transform.localRotation = Quaternion.identity; ruleListItem.transform.SetAsLastSibling(); var controller = ruleListItem.GetComponent(); // TODO: Set values // Save to the panel list ruleListItem.transform.SetParent(_pnlRelayRuleList, false); } _pnlRelayRules.SetActive(true); } Rendered camera: ![alt text][2] You can see the other (3D) menu that is rendered to the camera (which is overlayed and resized on the game's main camera) overlays ONLY the instantiated child. The hierarchy that is created with the above code is as follows: ![alt text][3] If I create pnlRule in the editor, things work perfectly fine - but when I add it programatically, it renders like this. I have messed about with layering and hierarchy ordering, as well as adjusting / removing / adding various layout components to test with, to no avail. Can anyone point me in the right direction? **UPDATE** I have since found that changing the second camera's view to orthographic mode sorts the problem. The problem I have here, though, is that the second camera needs to be in perspective mode! **UPDATE 2** I have just tried disabling a mask on pnlRuleList - this also makes the child elements render in the correct order, but obviously the mask no longer works! **UPDATE 3** OK, creating pnlRule in the editor also creates this problem. Sorry for the misinformation above! This is definitely a "Screen Space - Camera" + using a mask issue! **UPDATE 4** Another revelation! Just tried changing the lighting mode; I use Deferred Lighting - changing it to Vertex or Forward lighting solves the problem. Again, not the desired effect, but at least I'm getting closer to a solution. [1]: /storage/temp/39184-hackinguirenderunderworld-2.jpg [2]: /storage/temp/39185-hackinguirenderunderworld-1.jpg [3]: http://i.imgur.com/khScWtV.jpg

Viewing all articles
Browse latest Browse all 16

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>