Random questions

Hey peoples, so I’m working on a game, and I’ve tried to go as far as I could without asking questions and just looking up everything and figuring it out from what I can find, but today’s probably going to be my last day with internet for a while, and has been down for like, forever -.- and I’ve spent so much time trying to deal with #1 that I figured I should just ask everything I’ve been wondering here.

[SOLVED]1. Does anyone know how to actually get data out of a DataTable in entirely in c++? All the results I find on the subject either crash the engine when I open up a blueprints tab for some reason, or just say to make a pointer and make a blueprint of the class and set the pointer with the unreal engine, but I need to do this in a struct, so I can’t really do that. I suppose I could make blueprints out of everything that calls the struct’s functions and just pass in the values, but I’d rather keep things as self contained as possible.

I would just make use a UObject instead of a struct, that way I could make a blueprint child, but I need to save a TArray of them, and I feel like saving an loading instances of classes would be more trouble than it’s worth. I’ve tried looking it up to see if I could, but I can’t find any useful results about the subject.

  1. I’ve got a struct that needs to know that my game instance exist, and what’s in it. So I included the instance’s .h file in the .h file of the struct. Problem is the game instance has an array of that struct, so I can’t expose the array to blueprints. I could just include the struct’s .h file in the instance’s .cpp file, but I can’t expose the array to blueprints if I do that. Any ideas? This isn’t really that important since I planned on doing everything in c++, but it would be nice to have the option of accessing it in blueprints.

  2. Is it just me or does the skysphere not really work? The clouds stay the same white no matter where the sun is, even though they should turn black during the night and red when the sun is rising/setting based on the color curve driving the cloud color. When I check it out in the blueprints, hovering over the return value of the “Get Linear Color Value” node in the “Update Sun Direction” function tells me “Variable is not in scope” instead of a color like it should. A while back, to confirm it’s not just me, I’ve watched just about every Day/Night Cycle tutorial there is out there, and I’ve never seen the clouds change color. No one else seems to notice/mind though.

[SOLVED]4. This has more to do with programming in general, but when I see people make enums, I always see them doing something like

enum class E_Days : uint8
	D_Sunday UMETA(DisplayName = "Sunday"),
	D_Monday UMETA(DisplayName = "Monday"),
	D_Tuesday UMETA(DisplayName = "Tuesday"),
	D_Wednesday UMETA(DisplayName = "Wednesday"),
	D_Thursday UMETA(DisplayName = "Thursday"),
	D_Friday UMETA(DisplayName = "Friday"),
	D_Saturday UMETA(DisplayName = "Saturday")

Question is, what’s the point? Why not just put Sunday, Monday, etc. instead of putting the D_ in front? The “class” after “enum” should deal with any other enums with stuff with the same name shouldn’t it?

Sorry for the run on sentences and lack of pictures. My internet is super slow these days and trying to upload a picture is sure to fail -.- Thanks in advance for any help

  1. DataTables in C++

First you need to define the struct that will hold the information stored in a row. When you create the data table in the editor it will prompt you to pick which FTableRowBase to base the table off of.
This is a simple example of a data table that would just hold a bunch of FText values per row.

struct FDataTableInfo : public FTableRowBase


	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Data)
	FText Info;

Next, you will need to load the actual data table in C++. This code will attempt to find the data table if it’s already loaded, or load it as a fallback.

FString Path = FString(TEXT("PathToDataTable"));

UDataTable* LoadedTable = Cast<UDataTable>(StaticFindObject(UDataTable::StaticClass(), NULL, *Path));
if (!LoadedTable)
	LoadedTable = Cast<UDataTable>(StaticLoadObject(UDataTable::StaticClass(), NULL, *Path, NULL, LOAD_None, NULL));

Finally, you can use the data table that you have created and loaded in.

TArray<FName> Rows = LoadedTable->GetRowNames();
FDataTableInfo FirstRowData = LoadedTable->FindRow<FDataTableInfo>(Rows[0], FString());

You can iterate over that array and get all the rows in the table or grab a random index for example.

  1. Hard to say how to solve this problem without knowing more info. Usually structs are only used to store data and shouldn’t really need to know about your GameInstance. It makes perfect sense that your GameInstance would need a reference to the struct.

Forward declaration may be able to solve this problem however. You can declare a variable of your struct’s type without including a reference to it this way.
If your struct is named FTestStruct,

UPROPERTY(BlueprintReadWrite, EditAnywhere)
TArray<class FTestStruct> TestStructs

would declare an array of the struct without needing to include a reference to the struct’s header file. This way you could also expose it to blueprint.

  1. The reason this is done is simply because of naming conventions. Kind of like how Epic declares booleans with b infront of the variable name.

#1 Thanks dude! I can finally go to sleep -.- somehow no solution suggested using StaticFindObject at all.

#2 i’ve tried that, but it won’t let me compile. Error says that it has to be a UCLASS, USTRUCT, or UENUM. oh well, it really isn’t a big deal, I can finally focus on moving on thanks to #1. Seriously, thanks

#4. Alright, thanks. Just wanted to make sure nothing horrible would happen down the line if I just did my own thing.

Glad to hear :slight_smile:

Are you sure you are adding class before your custom struct type when you declare the variable? Maybe make sure you include the header in the .cpp of your GameInstance. Forward declaration should definitely solve your issue.

What do you mean? Am I supposed to go class struct name or struct class name? I’ve never seen anything other than struct name. either way I get an error when I try to compile.

So if you have a struct named FCustomStruct, normally you declare a variable of that type like

FCustomStruct MyStruct

BUT, if you want to declare the variable without including the header file, you do

class FCustomStruct MyStruct

So if you had an array of these structs instead of doing

TArray<FCustomStruct> MyStructs

you would do

TArray<class FCustomStruct> MyStruct

Yeah, I tried that, it wouldn’t let me compile due to the error. I’m just going to settle with going TArray<struct FCustomStruct> MyStruct without trying to let blueprints see it, because having it as TArray<class FCustomStruct> MyStruct doesn’t compile. If I really need to, I’ll figure something out (maybe).

Oh I’m an idiot, that’s exactly what you need to do. Blueprints should be able to see it if you add the UPROPERTY macro above it.
I blame the lack of sleep :rolleyes:

nah dude, that’s when I get the error. It only tells me that it needs to be a UClass, UStruct or UEnum when I put the macro on top.

Hmm I guess you can’t forward declare and use that macro. That sucks.

Pretty sure you can, because in this video, she does that at 7:20. Maybe you just can’t do it when it’s in an array or something.