Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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.

Product Version: UE 4.18
more ▼

asked Feb 24 '18 at 10:41 AM in Blueprint Scripting

avatar image

1 1 1 2

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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)
         && !It->HasAnyClassFlags(CLASS_Abstract))

more ▼

answered Feb 24 '18 at 03:37 PM

avatar image

37.3k 936 172 1116

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question