Search Feedback

144
votes

Garbage free Texture2D.GetPixels()

2D

-

-

The current signature of GetPixels is:
public Color[] GetPixels(int x, int y, int blockWidth, int blockHeight, int miplevel = 0);

if a version was added that didn't return an array but instead took a ref to the destination array as an argument the whole thing could be done without creating garbage for the GC to collect.

public bool GetPixels(int x, int y, int blockWidth, int blockHeight, ref Color[] dest_array, int miplevel = 0);

This is currently causing hitches due to GC when I blit sprites together in a character paperdoll system and it seems so easy to fix.

Comments (7)

  1. 304fecb756c290ed7315142485f6d1b2?d=mm

    NerdyOrc

    Jun 15, 2017 19:02

    I would add a Garbage Free EncodeToJpg, PNG and EXR

  2. 1ef09908cafdbc8ba06057af5b15ef30?d=mm

    npatch

    Apr 13, 2017 10:29

    Why don't you use Graphics.CopyTexture/Blit instead? Happens in the gpu. If its just blits that its.

  3. 4573505c10c98cecca1672a826ab2a02?d=mm

    Bibzball

    Feb 16, 2017 09:38

    I support this, there's no reason to keep creating a new array everytime when we could simply reuse it.

  4. 71d00689d1ac3d7060382f02e8ccde25?d=mm

    mark_isci

    Jan 27, 2017 15:40

    this is such a pain in the ass that i spent a long time writing my own thing to mirror the pixel data in something under my own control. you can use it too for $15 https://candle.itch.io/unity-bitmap-drawing

  5. 33c40919b6f814e5f07bacfd50e48d20?d=mm

    hurleybird

    Nov 11, 2016 21:56

    +1

  6. D68bba2ffa9cf7f3d9a23cc6a3071020?d=mm

    startselect_

    Oct 14, 2016 07:30

    I make ~20 GetPixels calls each frame for ~15 characters using the paperdoll system, the sprites are small but they add up. Calling GC.Collect every frame is obviously not going to work for me. I could offload this work to when equipment changes occur but then each character would have all their frames baked and each character would get a huge amount of required texture memory which sort of defeats the purpose of the paperdoll system.

  7. 536a9675e99c2bef0ded6ff4b53f082c?d=mm

    _Daniel_

    Oct 13, 2016 22:27

    LOL, I literally asked Unity Support this exact same question on October 11th. Something I've noticed, GC.Collect works very well with this, especially if you are making a bunch of GetPixels calls.

Your opinion counts

Help us make things better. Share your great idea for improving Unity or vote for other people’s.

Log in to post a new idea

Categories

All

(8665)

2D

(211)

Ads

(34)

AI & Navigation

(53)

Analytics

(85)

Animation

(288)

Asset Store

(202)

Assets

(480)

Audio

(149)

Cloud Build

(92)

Collaborate

(27)

Docs & Tutorials

(185)

Editor

(2005)

Everyplay

(13)

Game Performance Reporting

(10)

General

(786)

Graphics

(729)

GUI

(345)

Input

(140)

Licensing

(72)

Networking

(150)

Physics

(319)

Platforms

(397)

Profiling & Optimization

(66)

Runtime

(149)

Scripting

(973)

Terrain

(148)

WebGL

(128)