Creating custom content browser asset don't work

You forgot to change your 9th line in CustomAsset.h. You have:

class TESTPROJECT_API URobotCreationData : public UDataAsset

however your asset’s class is called UCustomAsset everywhere else in the code you provided. So it should be:

class TESTPROJECT_API UCustomAsset : public UDataAsset

(remember to change it in 13th line too)


Also, 5th line of your CustomAssetFactory.cpp should be:

#include "CustomAssetFactory.generated.h"

(without “U” at the begining)


And this is how your 3rd line in CustomAssetFactory.cpp should look like:

#include "CustomAssetFactory.h"

Again, no “U” at the begining.


File name shouldn’t include class prefix as well afaik (unless it’s a slate widget class, but it’s not the case).
So instead of having UCustomAssetFactory.h and UCustomAssetFactory.cpp you should have CustomAssetFactory.h and CustomAssetFactory.cpp. The same goes for your UCustomAsset.h and UCustomAsset.cpp.


I was playing with custom assets recently too, and from what I see here, I think there might be more problems after solving this one but i’m not sure yet. So let’s firstly fix compilation errors.

hi,
I am trying to create a custom content browser asset using UDataAsset and UFactory. Here is my code:

UCustomAsset.h:

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "Runtime/Engine/Classes/Engine/DataAsset.h"
#include "CustomAsset.generated.h"

UCLASS()
class TESTPROJECT_API URobotCreationData : public UDataAsset
{
	GENERATED_BODY()
public:
	UCustomAsset::UCustomAsset(const FObjectInitializer& ObjectInitializer);
	//~CustomAsset();*/
	UPROPERTY(VisibleAnywhere, BlueprintType, BlueprintReadWrite)
	int32 TestProperty;
};    

UCustomAsset.cpp:

// Fill out your copyright notice in the Description page of Project Settings.

#include "TestProject.h"
#include "UCustomAsset.h"

UCustomAsset::UCustomAsset(const FObjectInitializer& ObjectInitializer)
	:Super(ObjectInitializer)
{
}

UCustomAssetFactory.h:

// Fill out your copyright notice in the Description page of Project Settings.
#pragma once

#include "UnrealEd.h"
#include "UCustomAssetFactory.generated.h"

UCLASS()
class TESTPROJECT_API UCustomAssetFactory. : public UFactory
{
	GENERATED_BODY()

	UCustomAssetFactory.(const FObjectInitializer& ObjectInitializer);

	virtual UObject* FactoryCreateNew(UClass* Class, UObject* InParent, FName Name, EObjectFlags Flags, UObject* Context, FFeedbackContext* Warn) override;
};  

UCustomAssetFactory.cpp:

#include "TestProject.h"
#include "UCustomAsset.h"
#include "UCustomAssetFactory.h"

UCustomAssetFactory::UCustomAssetFactory(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{
	bCreateNew = true;
	bEditAfterNew = true;
	SupportedClass = UCustomAsset::StaticClass();
}

UObject* UCustomAssetFactory::FactoryCreateNew(UClass* Class, UObject* InParent, FName Name, EObjectFlags Flags, UObject* Context, FFeedbackContext* Warn)
{
	UCustomAsset* NewObjectAsset = NewObject<UCustomAsset>(Class, Name);
	return NewObjectAsset;
}

This doesn’t compile. It doesn’t like UCustomAsset Declaration, therefore it finds an error in every line that uses it.

VS shows an error is at the line with the UCLASS() in UCustomAsset.h
Error message is: this declaration has no storage class or type specifier

Also, I provide the link for the tutorial on which this code is based:

Hi,
Originally the asset was called “URobotCreationData”, but when I posted here, I decided to rename asset to UCustomAsset for simple. I forgot to do it in a few places. You found them. So, it isn’t the source of problem.
But I didn’t know that files must not start with “U”.
But still, thanks for your response.