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"

Casting a Struct? FTableRowBase

Is there a way to "cast" a struct? Specifically FTableRowBase child? I would like to retrieve a generic row from one of the data tables and then 'cast' it into a specific row in a function but I haven't figured out a way to do this yet.

Product Version: UE 4.20
more ▼

asked Feb 26 '19 at 10:49 AM in C++ Programming

avatar image

138 9 10 163

avatar image KristofMorva Feb 26 '19 at 12:36 PM

What stops you from using the generic Cast<>()? Does some problem occur?

avatar image Mercus Feb 26 '19 at 12:58 PM

No overload accepts argument type of FTableRowBase. Only accepts subclasses, WeakObjectPtr and Linkers i think?

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

1 answer: sort voted first

According to this post (https://forums.unrealengine.com/development-discussion/c-gameplay-programming/108339-can-use-use-inheritence-with-ustructs), unreal reflection system doesn't support it (hence the reason your Cast<>() might fail), however, I believe you should be able to cast them C-style (which is not safe however, so be sure you only do it when you're sure about the type):


more ▼

answered Feb 26 '19 at 01:17 PM

avatar image

1.4k 5 5 7

avatar image Mercus Feb 26 '19 at 01:42 PM

Yeah I attempted that but no suitable conversion supposedly.

Also tried making it - which compiled:

 FCustomTableRow* ChildRow = (FCustomTableRow*) &BaseRow;

But filled data was gibberish.

avatar image KristofMorva Feb 26 '19 at 03:00 PM

And are you sure your struct actually inherits from FTableRowBase?

avatar image Mercus Feb 27 '19 at 10:48 AM

Yeah, they are used in DataTables and just getting the row itself works fine, but casting it doesn't seem to work regardless of method that I've tried so far.

 struct FAmmoRow : public FTableRowBase
 //data here

avatar image KristofMorva Feb 27 '19 at 11:03 AM

I tried it out in C++, seemingly the FindRow function has a template, so you can use it like this:


It should return the corresponding type. You might also use GetAllRows the same way.

avatar image Mercus Feb 28 '19 at 12:51 PM

Yeah I'm already using that but what i'm trying to do is create a function that might retireve a row from one of many databases (each 'item type' has its own database - "legacy" issue so can't rework it at the moment).

I'm trying to create a function that would always return the basic type, which I would then cast to correct struct when using, but maybe it would work if I make it a template function instead (however that makes it unusable in BPs so its pretty much same as above.

Anyway, thank you for the help so far, if nothing else it gave me something to think about, just thought that there should be an easy way to cast derived structs but I guess it isn't that easy at the moment.

(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