Logging FColor type to get values in the output log?

So I tried, this is for INT logging, but it does not work with the FColor type, FColor type is really an int but may have other things as format go’s so I can’t log it.

Logging INT to output to log values.
UE_LOG(LogClass, Log, TEXT("int value %d"), PixelColor );

It looks like this :

FColor PixelColor;

I tried with a regular int and it does output values in the log but not with FColor. How could I see the values of PixelColor inside the log.

I mean this is basicly int

Why won’t it work.

It’s a union - just do %d,%d,%d with PixelColor.R, PixelColor.G and PixelColor.B

  UE_LOG(LogClass, Log, TEXT("int value %d,%d,%d"), PixelColor );

It does not work, maybe I’m not forming it in a proper way.

All I got is the PixelColor, all data is stored in that, I don’t have multiple variables for each channel.

Try:

UE_LOG(LogClass, Log, TEXT("int value %d,%d,%d"), PixelColor.R, PixelColor.G,PixelColor.B );

It’s good to know about the components there, R,G,B and A - 8 bits each. You can set the individual channels with those too.

UE_Log(LogTemp, Warning, TEXT(“Color %s”), *PixelColor.ToString());

It compiled but crashed my editor once I pulled the class out into the portview.
I’ll try blades stuff next.

Could it crash the editor because it has null values, I never got a crash before because there are no values provided by the logger.

Ouch! It shouldn’t be able to - try compiling in debug mode and set a break point just before logging that value - the debugger will show you if it’s valid. Is it possible the FColor is a pointer to a value rather than a value and is wrong?

So it’s missing a lot of things with this form
I’m missing some includes ?

The regular loger works with int.

FColor is the final value everything gets dumped in.

I got this from this forum, look.

Texture2DMipMap* MyMipMap = &texture->PlatformData->Mips[0];
    FByteBulkData* RawImageData = &MyMipMap->BulkData;
    FColor* FormatedImageData = static_cast<FColor*>( RawImageData->Lock( LOCK_READ_ONLY ) );

 


    uint8 PixelX = 5, PixelY = 10;
    uint32 TextureWidth = MyMipMap->SizeX, TextureHeight = MyMipMap->SizeY;
    FColor PixelColor;

    if( PixelX >= 0 && PixelX < TextureWidth && PixelY >= 0 && PixelY < TextureHeight )
    {
        PixelColor = FormatedImageData[ PixelY * TextureWidth + PixelX ];
    }
	RawImageData->Unlock();
int number = 31;	
	
      //UE_LOG(LogClass, Log, TEXT("My Int Value: %s"), *PixelColor);
	  //UE_LOG(LogClass, Log, TEXT("int value %d"), PixelColor );
	  //UE_LOG(LogClass, Log, TEXT("int value %d %d %d"), PixelColor );
	  //UE_LOG(LogClass, Log, TEXT("int value %d,%d,%d"), PixelColor.R, PixelColor.G,PixelColor.B );
	    UE_Log(LogTemp, Warning, TEXT(“Color %s”), *PixelColor.ToString());

I tried with int number and it outputs 31 in the log.
I want to see if it’s loading inside the FColor PixelColor anything.

for the loading of the texture I got:

static ConstructorHelpers::FObjectFinder<UTexture2D> Texture(TEXT("Texture2D'/Game/textures/Grainy_13_-_512x512.Grainy_13_-_512x512'"));
texture = Texture.Object;

So I want to log it to see if there is any data inside, it’s the only way to check before I go to the next step and manipulate those pixels.

Everything compiles fine, so from the constructor helper to the end I actually need to see if it’s loading the texture and texture data.
texture is loaded into the mip.

Texture2DMipMap* MyMipMap = &**texture**->PlatformData->Mips[0];

It’s then converted to 1D, from there you got some conditioning with pixelX and Y and if it passes that it will add the code data to pixelcolor, at least that is what it should do and I should get some INT color codes.

At the end you got.

PixelColor = FormatedImageData[ PixelY * TextureWidth + PixelX ];

FormatedImageData is a 1d Array as I understand ?

It’s probably easiest to compile in debug mode, then look at that memory in the debugger with a memory watch.

By the way after it compiles I get 0x00 whatever code, this means it can’t find the allocated data and that the data is empty, the address data is empty.

So could the logger provoke this ?

You mean “FormatedImageData” is a nullptr?

Maybe try:

FColor* FormatedImageData = (FColor*)( texture->Source.LockMip(0));

I get a crash.
ssertion failed: LockStatus != LOCKSTATUS_Unlocked [File:D:/Build/++UE4/Sync/Engine/Source/Runtime/CoreUObject/Private/Serialization/BulkData.cpp] [Line: 652]

UE4Editor_Core
UE4Editor_Core
UE4Editor_CoreUObject
UE4Editor_Mypp_5535!ARmc02::CreateTriangle() [C:\Users\Backspace\Documents\Unreal Projects\Mypp\Source\Mypp\Rmc02.cpp:100]

line 100 is where the log is, I get this with the modified part.

It looks like this now.

//loads the variable of the constructor and points to the mips.

FTexture2DMipMap* MyMipMap = &texture->PlatformData->Mips[0];
    FByteBulkData* RawImageData = &MyMipMap->BulkData;
    //FColor* FormatedImageData = static_cast<FColor*>( RawImageData->Lock( LOCK_READ_ONLY ) );
    FColor* FormatedImageData = (FColor*)( texture->Source.LockMip(0));

// I get a pointer to load data to from as I lock the texture
FColor* FormatedImageData = (FColor*)( texture->Source.LockMip(0));

//Converts to 1d

uint32 TextureWidth = MyMipMap->SizeX, TextureHeight = MyMipMap->SizeY;

So the loger now produces different errors with different settings, I think maybe it is the loger and not the code it’s self.

That’s most likely you need to replace the “RawImageData->Unlock();” with “texture->Source.UnlockMip(0);”

Thanks man, I actually forgot to modify unlock part since I modified the one before:

FColor* FormatedImageData = (FColor*)( texture->Source.LockMip(0));

so it wasn’t matching with what I modified, it’s no longer crashing.

But I get
LogClass: int value 0,0,0 :smile:

From:
UE_LOG(LogClass, Log, TEXT("int value %d,%d,%d"), PixelColor.R, PixelColor.G,PixelColor.B );

I think this is going to be a long one.

Maybe I don’t know just asking.

FColor* FormatedImageData = (FColor*)( texture->Source.LockMip(0));

Not producing , I mean this is not the original code and the others said the original works, but I will try different textures.

1 Like

Thanks for the help REcourse Design once again.

LogClass: int value 11,11,11
With a grayscale image.

I have to check that pixel if it’s really 11, 11 ,11.
But ussually gray scale images produce these linear codes.

It’s a start towards the goooooodd :crossed_fingers:
Hope it go’s well

So this code actually reads the data.
Since I got some help , For who needs it.

For the Constructor.
In the header:
UTexture2D *texture;

In Cpp:

//Inside the constructor
static ConstructorHelpers::FObjectFinder<UTexture2D> Texture(TEXT("Texture2D'/Game/ground.ground'"));
texture = Texture.Object;


//In whatever function you want to make this.
 FTexture2DMipMap* MyMipMap = &texture->PlatformData->Mips[0];
    FByteBulkData* RawImageData = &MyMipMap->BulkData;
    //FColor* FormatedImageData = static_cast<FColor*>( RawImageData->Lock( LOCK_READ_ONLY ) );
    FColor* FormatedImageData = (FColor*)( texture->Source.LockMip(0));
 


    uint8 PixelX = 5, PixelY = 10;
    uint32 TextureWidth = MyMipMap->SizeX, TextureHeight = MyMipMap->SizeY;
    FColor PixelColor;

    if( PixelX >= 0 && PixelX < TextureWidth && PixelY >= 0 && PixelY < TextureHeight )
    {
        PixelColor = FormatedImageData[ PixelY * TextureWidth + PixelX ];
		
    }
	//RawImageData->Unlock();
	texture->Source.UnlockMip(0);


UE_LOG(LogClass, Log, TEXT("int value %d,%d,%d"), PixelColor.R, PixelColor.G,PixelColor.B );

I actually need to make a loop for the pixels to get them all.

1 Like