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 filler03 · Jun 25, 2012 at 09:31 PM · texturetexture2dsetpixelsgetpixels

Setting pixels on a texture?

I would like to draw a small crater texture on a plane in the spot that an object explodes. I know there are GetPixels() and SetPixels() functions for Texture2D, but what if I am using just a plain Texture? Also what is the best file format for doing stuff like this if I want to "blend" my crater texture onto the existing one. The main thing I need help with is the Texture vs Texture2D part of it. Any help would be appreciated.

Comment
Add comment · Show 6
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 whydoidoit · Jun 25, 2012 at 09:33 PM 1
Share

Don't use 4 spaces if you don't want you whole question to be one long line formatted as code :) I've fixed it for you this time.

avatar image filler03 · Jun 25, 2012 at 09:34 PM 0
Share

thank you i was wondering what happened there..

avatar image whydoidoit · Jun 25, 2012 at 09:34 PM 0
Share

What kind of texture is it then?

avatar image filler03 · Jun 25, 2012 at 09:41 PM 0
Share

its simply a Texture. If I call GetPixels() it throws an error saying that that can't be done with a texture. And I don't see what the difference is between these two texture types.

avatar image whydoidoit · Jun 25, 2012 at 09:43 PM 0
Share

What is it - in your project, something you loaded? Can you not cast it to a Texture2D?

Show more comments

2 Replies

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

Answer by Julien-Lynge · Jun 25, 2012 at 09:54 PM

According to the comments, your image is a jpg (that I'm guessing you imported to Unity and assigned to a public variable).

You have your variable defined as a Texture, but Texture is just a wrapper/base class for all the kinds of textures that Unity supports. Your imported JPG is always a Texture2D, even if you've assigned it to a Texture variable. You'll need to cast to Texture2D (or just define your variable as such in the first place), and then you'll have access to the get and set pixel functions.

BTW, if you want to understand what the various types of textures in Unity are, take a look at:

  • Texture2D

  • RenderTexture

  • MovieTexture

  • WebcamTexture

Before you actually do anything with a Texture (that's not common to all texture types, like getting the width and height), you have to cast it to one of these types.

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
avatar image
1

Answer by whydoidoit · Jun 25, 2012 at 09:52 PM

File format doesn't really matter - that's what the file is on your computer - it is imported into a different format (much bigger) in your game.

You can just cast your texture to a Texture2D like this:

    var myTexture : Texture2D = someTextureYouGot as Texture2D;

That will remove your downcast warning.

then use SetPixels32 and GetPixels32 if you can - it is massively faster.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Draw one texture on to another? Get Set Pixels. 0 Answers

Merging Textures At Runtime - Not Correct? 1 Answer

Resetting a Material's Texture After GetPixels/SetPixels 1 Answer

Setpixels leads to a blank texture? 1 Answer

Can't copy skybox faces to a cubemap sized texture without huge quality loss 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