Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 lktfl · Mar 03, 2013 at 03:38 AM · texturegraphicsupdatedrawgraphics.drawtexture

How to call Graphics.DrawTexture() in Update

How would you call Graphics.DrawTexture() from Update or any other function than GUI. I wanted to use Graphics.DrawTexture() instead of GUI.DrawTexture() just so I wouldn't have to call it from OnGUI but it only draws a texture if its in OnGUI().

 var texture : Texture2D;
 var rect = Rect(0,0,0,0);
 var color : Color;
 var mat : Material;
 
 
 function Update () {
 //I would like to call Graphics.DrawTexture() here
 }
 
 function FixedUpdate () {
 //Or maybe even here
 }   
     
 function OnGUI () {
 //But it only works here
    if (Event.current.type != EventType.Repaint){ //draws texture only in 3d space
       if(texture != null){
          rect.center = transform.position;
          Graphics.DrawTexture(rect, texture, Rect(0,0,1,1), 0, 0, 0, 0, color, mat);
       }
    }
 }

I don't get any errors but it just doesn't draw the texture when I call the function outside of OnGUI.

Thanks for any type of help.

Comment
Add comment · Show 2
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 WilliamLeu · Mar 06, 2013 at 01:09 AM 0
Share

Have you looked into the $$anonymous$$onobehaviour function OnRenderObject?

avatar image lktfl · Mar 06, 2013 at 01:32 AM 0
Share

Oh, Awesome. I had no idea that OnPostRender was repeatedly called. I had the dumb idea that it was only called once like Start or Awake. Post your reply so I can mark it as a right answer. Thanks

1 Reply

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

Answer by lktfl · Apr 08, 2013 at 04:05 AM

Ok, since that other guy wont post his answer as an answer;

since I care that unity answers is a database for all users, not just my personal questionnaire;

AND since I know that most users who have the same question will click on this page, look at it for 2 seconds and see that there's no official answer, then click off without really reading my question or the responses...


Answer Part:

OnRenderObject, if you want to call Graphics.DrawTexture() every frame you must call it from within OnPostRender().

Reason:

This is because (I'm assuming) Graphics.DrawTexture() draws the texture immediately. Update() runs before the next frame is rendered.

Therefore if you call Graphics.DrawTexture() in the Update() function or any other function that is called before the frame is rendered, it will not show up.

That is why you have to call it in OnPostRender() (Called after frame is rendered) or OnGUI() (called multiple times a frame) or just after the frame has been rendered.

correct me if I'm wrong


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

10 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

Related Questions

Getting Error "DrawGUITexture: Texture is Null" when using Graphics.DrawTexture in OnGUI() 2 Answers

Problem with Graphics.DrawTexture 0 Answers

Creating an outline around the opaque pixels on a plane. Outline should extend outside of plane. 0 Answers

water graphic problem 0 Answers

Graphics/RenderTexture Alpha Brush 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