How to extend UTexture?

I’m trying to extend it and, unless I don’t use UCLASS, it won’t compile. For now, I’m just trying to reproduce the UTexture2DDynamic class. When I get it to compile, I’ll change some of the functionality. But I can’t even compile it.

Here’s the header:

#pragma once

#include "Engine/Texture.h"
#include "DynamicTexture2D.generated.h"

UCLASS (HideCategories=(Object), MinimalAPI)
class UDynamicTexture2D : public UTexture
{
	GENERATED_UCLASS_BODY()
public:
	int32 SizeX;
	int32 SizeY;

	UPROPERTY(transient)
	TEnumAsByte<enum EPixelFormat> Format;

	int32 NumMips;
	uint32 bIsResolveTarget : 1;

	// Begin UTexture interface.
	ENGINE_API virtual FTextureResource* CreateResource() override;
	virtual EMaterialValueType GetMaterialType() override { return MCT_Texture2D; }
	ENGINE_API virtual float GetSurfaceWidth() const override;
	ENGINE_API virtual float GetSurfaceHeight() const override;
	// End UTexture interface.

	ENGINE_API void Init(int32 InSizeX, int32 InSizeY, EPixelFormat InFormat = PF_B8G8R8A8, bool InIsResolveTarget = false);

	ENGINE_API static UDynamicTexture2D* Create(int32 InSizeX, int32 InSizeY, EPixelFormat InFormat = PF_B8G8R8A8, bool InIsResolveTarget = false);
};

And here are the output messages:

1>------ Build started: Project: UE4, Configuration: BuiltWithUnrealBuildTool Win32 ------
2>------ Build started: Project: VirtuaFantasy, Configuration: Development_Editor x64 ------
2>  Creating makefile for VirtuaFantasyEditor (List of files containing UHT types has changed)
2>  Parsing headers for VirtuaFantasyEditor
2>    Running UnrealHeaderTool "[Path]\VirtuaFantasy.uproject" "[Path]\VirtuaFantasy\Intermediate\Build\Win64\VirtuaFantasyEditor\Development\UnrealHeaderTool.manifest" -LogCmds="loginit warning, logexit warning, logdatabase error" -rocket -installed
2>  [Path]/VirtuaFantasy/Plugins/UnrealSmartKinect/Source/UnrealSmartKinect/Public/DynamicTexture2D.h(15) : LogWindows:Error: Windows GetLastError: The operation completed successfully. (0)
2>  [Path]/VirtuaFantasy/Plugins/UnrealSmartKinect/Source/UnrealSmartKinect/Public/DynamicTexture2D.h(15) : LogWindows:Error: === Critical error: ===
2>  Assertion failed: FoundClass [File:D:\BuildFarm\buildmachine_++depot+UE4-Releases+4.10\Engine\Source\Programs\UnrealHeaderTool\Private\HeaderParser.cpp] [Line: 4410]
2>Error : Failed to generate code for VirtuaFantasyEditor - error code: CrashOrAssert (3)
2>  UnrealHeaderTool failed for target 'VirtuaFantasyEditor' (platform: Win64, module info: [Path]\VirtuaFantasy\Intermediate\Build\Win64\VirtuaFantasyEditor\Development\UnrealHeaderTool.manifest).
2>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.MakeFile.Targets(37,5): error MSB3073: The command ""C:\Program Files\Epic Games\4.10\Engine\Build\BatchFiles\Build.bat" VirtuaFantasyEditor Win64 Development "[Path]\VirtuaFantasy\VirtuaFantasy.uproject" -rocket -waitmutex" exited with code -1.
========== Build: 1 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

It may be that you’re using ENGINE_API outside the engine module? Try removing them.

Thanks for your answer! :slight_smile:

I did remove those ENGINE_API because of dll linkage errors. But it keeps giving the same error.
The weird thing is that if I try to inherit from UObject and delete all properties from the class, it keeps giving the same error, whereas in other classes I’m doing UCLASSes from UObject just fine. There something really weird going on here. And I can’t find anything about that Assertion failed: FoundClass in the HeaderParser.

Now, I’m removing the headers and cpp of this class from the project. Then, I’ll create new UObject class to test and see if it compiles.

Ok… this is realy weird!

I removed the .h and .cpp files of the offending class from the project and started over with new ones, writing exactly the same stuff (event copying/pasting). It worked! It compiled ok! I have no idea why.

Could it be some Unreal Header Tool bug?