How to reference an asset from data table in Blueprints?

I’ve found THIS and THIS, but both tutorials are for C++. Is it possible to, for example, read a path of an asset from data table (csv) and spawn it via Spawn Actor From Class? Or reference an asset from data table in some other way?

in one of links there’s FindObject method for C++, it returns UObject that is parent class for all game objects, so try just cast object of this reference into class with same name

for example, you have blueprint called “BP_MyActor”, after saving and retrieving UObject reference from FindObject try cast variable with this reference to “BP_MyActor” and save result in variable of such class of course, then you can expose this variable to blueprints or return it to blueprints as reference to store in variable made right in blueprint

Thanks, but it involves digging into C++, and i mean if it is possible only via Blueprint scripting. For example, i have my .csv data table with quest data. It includes quest name, quest conditions, etc., and quest reward. In “quest reward” column i could put a path to an asset (like in these tutorials), but looks like it works only with C++? :frowning:

If so, maybe i will have to type in item names there, and somehow hardcode them in my blueprint (switch on string → if “potion” spawn actor potion, if “sword”, spawn actor sword, etc…) - Quite tedious, but i can’t figure out any other way, if asset paths don’t work without digging in C++…

Hi,

i got idea for you, probably there are 2 implementations of save system:

  1. one on these links that work mostly in automatic way, use objects referencec and so on, but require using C++
  2. the other one is more time wasting, but still possible through blueprints only and below more details how you can achieve it

to make blueprints only saving you probably need to make association array between text class name and object reference, best container will be array of structures, structure should have at least 2 variables inside:

  1. string/name where you can put text class name of any objects or just associate any actor/object class with a custom string
  2. just variable with type “actor” or “object” where you can put any reference to any actors/objects

when you need save:

  1. iterate your game objects for save over such array to get associated text name
  2. save list of such text names in any common way (gues there was few ways, but i don’t remember where i saw tutorials, guess you can search how save strings between game launches)

when you need load:

  1. iterate your saved text strings over arrays of these structures to get objects references
  2. spawn these objects by references you got

if you need store any values for objects, like HP, MP, Ammo - just write loops to get values from variables and represent it as strings, like “hp:100500”, of course you will need make one more loop to set objects properties from text

to get text reference to instance of object just use “get display name” in this case for example:

you have blueprint called “BP_enemy_pig” with actors and anything else inside, when you “get display name” you’ll get string like “BP_enemy_pig№”, where № will be unique number of current object instance, so if you make multiple enemy pigs, they most likely will have display names “BP_enemy_pig1”, “BP_enemy_pig2”, “BP_enemy_pigN+1” where N+1 is just iterator number for base class name, so from this point you can get not only associated text class representation, but also a reference to exact instance of object and your whole strings for saving objects in blueprints may look like this:

common template - “base class name”;instance number;values string1,values stringN
example “BP_enemy_pig”;1;hp:100500,mp:0,lvl:10

note that ; is separator for common properties and , is separator for just values of object, like ho, mp, level and so on

Array of structures with ID association is probably the way to go :slight_smile: Thanks for the hints!