Hi, i want to create an inventory system, but i don’t want to use Structures because they are still bugged. (See here).
Question 1: I think that there is no need to spawn an “Item” as actor and attach it to a Object Inventory, just for performances purpose.** It is a proper thinking?**
They are. You really have to go out of your way to instantiate UObjects without them getting cleaned up during world teardown. (See: RF_RootSet, AddToRoot, etc.) And if you do end up with a lingering object in the end, the engine will throw all sorts of warnings at you.
What you’re seeing is simply the internal counter incrementing with each instance. This counter allows object names to be unique without having to manually name each one of them.
The instances are being destroyed. The counter value persists for as long as the engine is running, which in the editor can span across multiple PIE sessions.
See for yourself, put a TObjectIterator somewhere in your code:
That’s not something that’s commonly done… Normally you want to use classes transparently, regardless of if they were implemented in blueprint or native. It might help knowing what are you trying to achieve by checking this class?
In any event, assuming UObjectChildClass is the base class you want to use for your inventory system… You already know that it is not a blueprint class since it is a native base. However, if you have an instance of such an object, you can call GetClass() on it to get the actual class of the object. For objects implemented in blueprint, GetClass() will return a special kind of class, UBlueprintGeneratedClass, which contains extra information about the blueprint data. But as mentioned, you rarely have reason to operate on those.
The answer to your first question (in my opinion) is yes. I have built my own inventory system utilizing UObject, however there is a caveat to that. As it stands Actors are the only things that do network replication, base UObjects can only be replicated FROM an actor (even though actors are UObjects, Actors are the first in the class hierarchy to implement network replication), UActorComponents support replication but still utilize the owning actor for network replication. So if your game is single player you have nothing to worry about, however if your game is multi-player (like mine) then figuring out replication will be a royal pain as I have found the documentation is severely lacking on the C++ side.
Your second question was answered by cmartel and I cannot answer it any better than he/she