x

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"

Data Table into Array

Hello,

I have Data Table of Elements, each element contains parameters like Name, ProtonNumber, Weight, etc..

And I would like to convert it into array of elements. So I created element class, as you can see below, it is dummy class just for holding variables. element class image

And in Level Blueprint I want to fill array with these elements as you can see below.

Index of array should be ProtonNumber (because it is unique and it is number), and others parameters like Symbol, Name, Weight etc.. should contain elements in that array.

For example array with index 1 (pseudo code):

 Elements[1]->Name;
 Elements[1]->Symbol;
 Elements[1]->Weight;

DataTable into Array image

How to convert it?

Product Version: UE 4.15
Tags:
more ▼

asked Apr 24 '18 at 05:34 PM in Blueprint Scripting

avatar image

t0msk
67 10 16 22

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

1 answer: sort voted first

Instead of Setting the array, Get it and Add element. Something like this:

alt text

The array type needs to match whatever the loop is spitting out, of course.

capture.png (49.0 kB)
more ▼

answered Apr 24 '18 at 05:59 PM

avatar image

Everynone
15.2k 77 25 62

avatar image t0msk Apr 24 '18 at 06:33 PM

But it is array of names and I need to convert it somehow to array of my custom elements as you can see below.

linking error

avatar image Everynone Apr 24 '18 at 07:01 PM

What is a BP Element? A component, an actor? Anyway, you can't directly compare a piece of text with an object... There is no conversion.

Your DataTable holds structs, you can populate your array with structs.

You can spawn (SpawnActorFromClass node) objects / components and feed them data from the Data Table and then add those objects / components to an array. I believe this is what you're trying to achieve.

avatar image t0msk Apr 24 '18 at 07:49 PM

As I said BP Element is just dummy class (actor with no logic) only hold these variables.

Equivalent to C++:

 class Element {
    public:
       double a;
       double b;
       double c;
 };
 std::vector<Element> element;

BP Element

avatar image Everynone Apr 24 '18 at 09:54 PM

So what's the problem then? Spawn the actor (instantiate), feed it DataTable struct/variables, add the actor to the array.

You can either have your dummy hold the struct or use separate variables - you can even expose them on spawn, making them easier to set.

Something like this:

alt text

capture.png (102.0 kB)
avatar image t0msk Apr 24 '18 at 10:27 PM

But this spawns it in the world, right? I don't want to spawn it in the world, just make array in the background.

avatar image Everynone Apr 25 '18 at 07:48 AM

Yes, they spawn in the world - persistent level. Just keep it hidden. If you just make an array of objects, it will be a linked list of null pointers since no objects were instantiated.

If you want pure data, keep it as a struct.

You seem to want objects, but you don't want to construct them?

avatar image t0msk Apr 25 '18 at 10:28 AM

Yes I want only pure data without any other logic or construction, so I left it as array of struct (I didn't know that option).

I want object (class) like in programming language like:

 class Element {
     public:
        double a;
        double b;
        double c;
 };

And struct looks like this, so I don't need that BP actor :) Thank you

avatar image Everynone Apr 25 '18 at 10:32 AM

Yup, you can keep it as a struct array. Easier to manipulate, iterate and so on; especially that you cannot write anything back into the DataTable.

For anyone with some programming background, blueprints may seem somewhat awkward at times :)

(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