Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by rafa3dm · Nov 07, 2015 at 03:09 PM · rendertextureprefab changing at runtimetargettexture

create Render Textures at runtime

Hello there,

I'm wondering if anyone can help me. I am bit lost and haven't been able to find any information that could help me here or anywhere on the internet.

I want to create several CCTVs at runtime. This is because I may need to create 10 or 50 or 25 CCTVs or "screens" depending on the outcome of the gameplay.

So, I read it was possible to create Render Textures at runtime. I am using c#.

Here's what I have tried:

 public GameObject CCTVScreenPrefab; //Prefab Added via the Inspector
 public GameObject CaptCamPrefab; //Camera Prefab Added via the inspector
 
 void Start () 
 {
     GameObject CCTVScreen = Instantiate(CCTVScreenPrefab) as GameObject;            
     GameObject CaptCam = Instantiate(CaptCamPrefab) as GameObject;
 
     //Creating a render texture at runtime:    
     RenderTexture RefTexture = new RenderTexture(256, 256, 24, RenderTextureFormat.ARGB32);
     RefTexture.Create(); // Not sure if I really need this.
 
        //Linking everything:
        CaptCam.GetComponent<Camera>().targetTexture = RefTexture ;
        CCTVScreen.GetComponent<Material>().SetTexture("_MainTex", RefTexture);
 
         //I tried this too: CCTVScreen.GetComponent<Material>().mainTexture = RefTexture;

But it won't work. What am I doing wrong? I really don't want to create 50 render textures on the scene if I don't need them. Just the number of cameras and the number of render textures and the number of "screens" or objects to display such texture at runtime.

I tried the standard shader as a material for all these objects or "screens". Ideally, the mobile/diffuse shader would be better as the simulation is for mobile phones and tablets.

I am also using at the moment Unity 5.2 Personal. For what I have researched, Render Texture is available for Unity versions greater than 5.0.

Thank you very much for your help.

Comment
Add comment · Show 1
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 rajanerve · Mar 21, 2018 at 09:38 AM 0
Share

Hello. did u find the solution for your problem, is so please share the example code?

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Bunny83 · Mar 22, 2018 at 02:50 AM

This line:

 CCTVScreen.GetComponent<Material>().SetTexture("_MainTex", RefTexture);

doesn't make much sense as Material is not a Component. What you want to do is accessing the Renderer of the screen object and change the texture of the material of the Renderer

 CCTVScreen.GetComponent<Renderer>().material.mainTexture = RefTexture;
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

33 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

Related Questions

Render Texture from Cameras targetTexture produces seams. 1 Answer

UI Canvas to RenderTexture and to main screen at same time. 0 Answers

Problem with camera Rendering 2 Answers

Capture Screenshot on Linux Headless Machine 3 Answers

Wrong Coloring (Sometimes) when capturing "Screen"-shot 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