Get Item By ID

Ok, so I want to make an item spawning system to make my life easier than individually placing the items in the world. I have assigned each item a Integer Variable called ID. Every item is a child of my BPMasterItem. I want the player to be able to type in the ID of the item and for it to be spawned. How would I go about searching for an ID equal to the input ID from only the master item? Is there like a ForEachChildren node or a way I can set something like it up?

Thanks in advance.

If you blueprint only then best way for you is to do it manual way, by simply making Integer to Class Map varable in some blueprint (GameMode for example) and manually assign integer IDs to Classes in varable defaults and they use them in spawning commands. You can use array if you don’t plan to make gaps between ID numbers, but map is a lot easier to manage in property editor. Thats what best you can do in blueprint for what you want to make.

This is impossible to make it automatic in Blueprints because you need to use TObjectIterator to search all classes object (UClass objects) and then create array or integer map of classes based from BPMasterItem, which is long process and should be done on game start up possibly on game code module start up as it freeze up engine for a bit if you do that in main game thread. Alternatively trying to do something when Default Class Object of your classes is constructed which should be bit faster but that it still requires C++. Blueprint can’t really do anything beyond world, not to mention look up for classes.

You would need to make create TMap<int32,UClass*> Classes; in some class you will be able to access in blueprints (GameInstance is best bet for you, it gets more complicated in other global classes that are not much accessable for blueprints), create C++ class as base for your blueprints which i name here AMasterItem, in it place int32 ID; with UPROPERTY(EditDefaultsOnly, Category=“ID”); (it will make ID varable editable only in defaults) parent your BPMasterItem with MasterItem class and do something like this somewhere on start up:

for(TObjectIterator<UClass> It; It; ++It)
{
	if(It->IsChildOf(AMasterItem::StaticClass()) 
		&& !It->HasAnyClassFlags(CLASS_Abstract))
	{
		Classes.Emplace(It->GetDefaultObject<AMasterItem>()->ID.*It);
	}
}