Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
0
Question by pixelthis · Aug 06, 2010 at 05:12 AM · camerainstantiateguitexturebackgroundculling

Dynamically instantiated game objects not showing in main camera (with background camera)

Hi all,

I have followed the instructions here to create a background image in a second camera. The main camera is set to ignore the background layer (culling mask has everything except background), and the background camera is set to only see the background image (only background is set in culling mask).

My code instantiates many game objects dynamically. These are not visible in my scene - it looks like they are behind my GUITexture because when I click run in the editor I can see them in the scene window, just not in the game window.

Any ideas?

Comment
Add comment
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

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by pixelthis · Aug 08, 2010 at 10:43 PM

I have done some more testing, and this seems to be an editor quirk/bug.

For example, quitting and restarting Unity resolves this issue - until I change the scene view (e.g. zoom in/out), after which it stops working again. Making an unrelated code change in a script then fixed it again. And so on...

I am using Unity Free (2.6) on Windows Vista.

Comment
Add comment · Show 3 · 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 Eric5h5 · Aug 08, 2010 at 11:01 PM 0
Share

Sounds like maybe you haven't set the camera depths properly. Having two cameras with the exact same depth results in random behavior like that, since there's no deter$$anonymous$$istic way to tell what camera will render on top.

avatar image pixelthis · Aug 09, 2010 at 07:53 AM 0
Share

The cameras have different depths and are in different locations. Should I set the background camera to have the shortest depth?

avatar image Cyb3rManiak · Aug 09, 2010 at 02:11 PM 0
Share

The background camera should have the lowest depth, so set it at depth of -500 just to be sure you're not getting confused (yes, that's a $$anonymous$$us sign).

avatar image
0

Answer by AliAzin · Aug 06, 2010 at 06:38 AM

you should put your new objects into its layer. like this:

gameObject.layer = 5; // 5 is the number of its layer
Comment
Add comment · Show 2 · 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 pixelthis · Aug 08, 2010 at 08:32 PM 0
Share

I don't think that is the problem. Does Instantiating a game object place it on my user-defined background layer by default?

avatar image pixelthis · Aug 08, 2010 at 10:44 PM 0
Share

Thanks for your help AliAzin - in the end it turns out it is probably editor related.

avatar image
0

Answer by Cyb3rManiak · Aug 09, 2010 at 02:55 PM

In the mean while, if you want to try another way while you're designing the game - try creating this C# script (CreateBGPlaneOnCamera.cs) and attaching this to your BG camera. Set nBackgroundLayerID to the BG layer number, and assign a texture to txBackground. It should get ya there quick and dirty.

When you're ready to stop playing around, just return to using the GUILayer approach, since I don't think that quirk/bug will happen in a built player.

using UnityEngine; using System.Collections;

public class CreateBGPlaneOnCamera : MonoBehaviour { public Texture2D txBackground; public int nBackgroundLayerID;

 void Start () 
 {
     GameObject plane = GameObject.CreatePrimitive(PrimitiveType.Plane);
     plane.renderer.material.shader = Shader.Find("Transparent/VertexLit");
     plane.renderer.material.color = new Color(0.5f, 0.5f, 0.5f, 1f);
     plane.renderer.material.SetColor("_Emission", new Color(0.5f, 0.5f, 0.5f, 1f));
     plane.renderer.material.mainTexture = txBackground;
     plane.gameObject.layer = nBackgroundLayerID;
     plane.transform.parent = transform;
     plane.transform.localScale = new Vector3(Screen.width * 0.1f, 1f, Screen.height * 0.1f);
     plane.transform.localRotation = Quaternion.Euler(-90f, 0f, 0f);
     plane.transform.localPosition = new Vector3(0f, 0f, Screen.height * 0.5f / Mathf.Tan(camera.fov * 0.5f * Mathf.Deg2Rad));
     camera.farClipPlane = plane.transform.localPosition.z;
 }

}

Comment
Add comment · 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

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

No one has followed this question yet.

Related Questions

How can I display a flat background - 2D image, not a skybox - behind everything in my camera? 4 Answers

Instantiated GuiTextures not showing 1 Answer

make camera background cull everything 1 Answer

Camera Culling mask/ background color issue. 0 Answers

GameObject Instantiated Off Camera 0 Answers


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