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
9
Question by Vince · Aug 24, 2010 at 03:14 PM · textureraycastmemorypixel

Trying to access a texture's pixel coords.

I'm attempting to access a texture's pixel coord's to pull out what color is at that specific coords. Right now I am firing a raycast at an specific object (in this case a laptop) pulling off the objects textureCoords, then looking those coords up on a stored texture "laptopstatic_handling" in the Resources folder. I am getting a Unity error that says:

UnityException: Texture 'laptopstatic_handling' is not readable, the texture memory can not be accessed from scripts. You can make the texture readable in the Texture Import Settings. RayCastController.Update () (at Assets/RayCastController.cs:35)

Not quite sure what that means. Here is the sample of code

// Use this for initialization void Start () { tex = (Texture2D)Resources.Load("laptopstatic_handling"); }

// Update is called once per frame void Update () {

 RaycastHit ray = new RaycastHit();
 if(!Physics.Raycast(UnityEngine.Camera.current.ScreenPointToRay(Input.mousePosition),out ray)){
     return;
 }

 name = ray.collider.gameObject.name;

 Renderer renderer = ray.collider.renderer;
 MeshCollider meshCollider = (MeshCollider)ray.collider ;

 //Check to see the collider has a renderer and texture
 if (renderer == null || renderer.sharedMaterial == null ||
     renderer.sharedMaterial.mainTexture == null || meshCollider == null){
     return;
 }


 Debug.Log( tex.GetPixel( (int)ray.textureCoord.x,(int)ray.textureCoord.y).ToString());

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 Lord-Megabite · Jan 31, 2016 at 02:36 PM 0
Share

A picture is worth a thousand words!

res1.png (45.3 kB)

2 Replies

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

Answer by Wolfram · Aug 24, 2010 at 03:41 PM

Well, why not simply do what the error message suggests: go to the texture "laptopstatic_handling" in the Project tab, then in the Inspector enable "IsReadable" in its import settings (NOTE: you need to change the Texture Type to "Advanced"). From the GetPixel() docs:

"The texture must have the Is Readable flag set in the import settings, otherwise this function will fail."

Comment
Add comment · Show 4 · 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 Vince · Aug 24, 2010 at 03:44 PM 0
Share

I completely skipped over that sentence. Thanks, works now.

avatar image Demigiant · Mar 15, 2012 at 08:03 PM 2
Share

Uhm, I'm getting crazy here. Using Unity 3.5, I can't find anywhere the isReadable checkbox in the textures Inspector... What am I doing wrong?

avatar image Cyrille-Paulhiac · Mar 24, 2012 at 03:11 PM 3
Share

You can find this Checkbox by choosing "Advanced" in the "Texture Type comboBox.

It is called "Read/Write Enabled"

avatar image mrpmorris · Feb 24, 2013 at 12:03 PM 0
Share

If you add the steps to your answer to change the mesh + change the material to "Advanced" and enable read/write I will be very happy to accept your answer.

Thanks so much!

avatar image
0

Answer by Redlazer · Mar 18, 2012 at 10:13 PM

You're looking for "Is read/write Enabled"

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Get pixel from Rotated Texture2D 1 Answer

How can i avoid mouse clicking on alpha areas in my GUITexture? 1 Answer

How can I tell how much grahics memory is available? 1 Answer

Parenting Bullet Holes? 1 Answer

RayCast Hit 2 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