Unity scripting api texture2d. To get pixel data more quickly, use GetPixelData instead.
Unity scripting api texture2d. Use Unity to build high-quality 3D and 2D games, deploy them across mobile, desktop, VR/AR, consoles or the Web, and connect with loyal and enthusiastic players and customers. OnPreprocessTexture. Texture. Oct 3, 2025 · Unity sets all pixels of this Texture to transparent black (0,0,0,0). A slice of the data will be returned according to the requested mip level. texture will be in TextureFormat. Even if Apply is called on a texture asset with data stored on disk, Unity will no longer try to reload from disk if once it discards the CPU copy, since the readable texture data might have been altered. If the pixel coordinate is outside the texture's dimensions, Unity clamps or repeats it, depending on the texture's TextureWrapMode. ComputeMipmapSize API to calculate the size of a mipmap level. You can use the returned array with LoadRawTextureData. g. On some platforms and APIs the contents will default to black, but you shouldn't depend on this. On Android, you can request it at runtime using the Permission API. isReadable becomes false. This function is very similar to the texture constructor, except it works on existing texture object. This function is mostly useful for native code plugins that create platform specific texture objects outside of Unity, and need to use these textures in Unity Scenes. For details on those methods, see the ImageConversion documentation. On iOS and WebGL, you can request camera permission at runtime using Application. If you don't need a copy or if you want to modify the data directly, use the version of this function that returns a NativeArray, or Texture2D. Reinitialize instead. Use this to create textures on the fly or to modify existing texture assets. Description Resizes the texture. 4 days ago · Unity sets all pixels of this Texture to opaque white (1,1,1,1). Upgrade to Boolean) Declaration public bool Resize (int width, int height, TextureFormat format, bool hasMipMap); Unity throws a UnityException if either texture is unreadable, and throws an ArgumentException if CopyPixels fails. This function returns the raw texture data as a byte array, which you can then use with Texture2D. usual 32 or 16 bit render texture). This version of the GetRawTextureData method returns a copy of the raw texture data on the CPU. The initial contents of a newly created render texture are undefined. But to render the updated texture, you must use Apply to copy it from the CPU to the GPU. GetPixels might be slower than some other texture methods because it converts the format the texture uses into Color Description Class for texture handling. If you want to change compression format based on filename or other attributes of the texture, use AssetPostprocessor. GetPixelData. This method gets pixel data from the texture in CPU memory. To use Texture2D. The size of the array is the width × height of the mipmap level. Note: On Android and iOS platforms, Unity doesn't support This function works on RGBA32, ARGB32 and RGB24 texture formats, when render target is of a similar format too (e. Unity is the ultimate game development platform. Unity uses bilinear filtering to return the pixel color. If the input textures can't all fit into a texture atlas of the desired size then they will be scaled down to fit. Use this class to create textures, or to modify existing texture assets. isReadable must be true, and you must call Apply after LoadRawTextureData to upload the changed pixels to the GPU. If the CPU copy exists, you can read from and write to the CPU copy more flexibly than the GPU copy, for example using GetPixels. You can also use the following to write to a texture: Texture2D. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable. Use this to compress textures at runtime. Perform texture operations in Use this class to create textures, or to modify existing texture assets. You can't choose a compression format at this point. This allows you to serialize and load a textures of For most types of textures, Unity can store a copy of the texture in both CPU and GPU memory. GetPixels, you need to select Read/Write Enabled on Texture Import Settings to enable access to the Texture data from scripts. Apply is an expensive operation because it copies all the pixels in the texture even if you've only changed some of the pixels, so change as many pixels as possible before you call it. Note: When you use the Unity APIs to modify the pixel data of a Texture object, it changes the underlying graphics API native pointer. After resizing, texture pixels will be undefined. GetNativeTexturePtr. This happens because of alignment restrictions on compressed texuture formats. CoreModule Leave feedback Unity is the ultimate game development platform. CoreModule Leave feedback The ImageConversion class provides extension methods to this class that handle image encoding functionality. lzj ztkoqf9 w4bbp touv8sp rlb ofmxa zilv qku pwyr qlxgil