Unrecognized type "Item" - type must be a UCLASS

Hey guys, another question of mine: I´ve created a Itemclass which extends from UObject, I´ve also included the Item.h in the pickupclass where I´m getting the error in and I have no clue, why I´m still getting it.

225034-screenshot-48.png

Hey there, can you show or paste both of the classes?

You are using a normal c++ workflow with constructor / destructor and creating the instance with new and that is not the correct way of doing that in unreal because he has its own garbage collection and workflow. The correct way is the to use newobject. If you search for newuobject or create uobject you’ll find articles about that.

Hi,

There are a few serious flaws here in your code that you should pay very close attention to. First, Your Item class is inheriting from UObject and that means that it cannot be initialized with c++ generic keyword new. Since you are initializing your Item class during runtime in a member function, you must initialize it with the Unreal Engine provided factory method NewObject<Item>(this).

Second, even if you use NewObject for initialization, your Item will automatically gets garbage collected. To prevent the garbage collection from kicking in and destroying your object, you must make a strong reference to it via UPROPERTY() macro. From your code it appears that you need more than 1 single object, so you should consider using TArray to store their references there. Please refer to engine documentation in here to learn more about UObject handling. You can also learn more about how to initialize UObjects, things to consider and some good coding practices in my other answers here and here.

Hope this helps.

Thanks for the answer :smiley: It is pretty well explained^^ I´ll try to redo it tomorrow :smiley:

Thank you for making things clear :smiley:

You’re welcome. You must also mark your Item class with UCLASS() macro as @IGorilla pointed out.

add UCLASS() above your item class