Need more detail on new concepts use but not explained in the lesson

There are 2 things that are new in this lesson that is completely glossed over without any detailed explanation.

  1. I believe this is the first time we are using struct as type and there is no explanation of what it is and how it’s differ from other types.

  2. In the CPP file, while #include “BehaviorTree/BlackboardComponent.h” is a slightly new format. Why does BehaviorTree/ as a directory needs to be included. Why isn’t directories before BehaviorTree/ included in this syntax? What are some sample situations that needs to use this format? Please explain in detail.

Thanks!

struct was used in BullCowGame, basically the same as class but members are public by default.

That is the file path, the header is in a directory called “BehaviorTree”.

1 Like

Sorry, but you have answered none of my questions.

  1. I asked about struct, because the syntax and the usage in this case is quite different than when we used it briefly in Bull Cow Game. It’s returning a type “struct”, which is like saying return a type “class”, which is quite confusing to me.

  2. I understand it’s the file path and I even said so in part of the questions. What I want to know is why is it used in this case? Why only include 1 parent folder and not any directory above that? What are some situations that needs to use this format as oppose to only include the file name as we normally do.

What is? and are you sure it doesn’t say struct Name just like it would class Name?

Apologies, I got distracted whilst reading and answering and forgot I hadn’t fully read the question.[quote=“Richard_Yao, post:3, topic:7325”]
Why only include 1 parent folder and not any directory above that?
[/quote]

Because certain paths are known to Unreal, and this usage is already in your code, if you look at some of your headers you will see 'GameFramework/" or “Components/” etc. Some will be in seen directories and some won’t
[quote=“Richard_Yao, post:3, topic:7325”]
What are some situations that needs to use this format as oppose to only include the file name as we normally do.
[/quote]

Basically, if you get a compilation error, check the docs page and scroll to the bottom for “references” and it should tell you the path i.e ~/Classes/BehaviorTree/BTTaskNode.h and wanting the stuff after “classes”

Thank you very much on the reference explanation.

On the struct part, I reread the code and realized you are right. I misunderstood the code completely. It is spelled out as FBlackboardKeySelector name. Now I have another questions about this. Why do we need to include the struct in front of the FBlackboardKeySelector type? Why do we not do this for class?

Just realised this question was tagged with a lecture I haven’t done. However looking at the code on Github, I am not really sure idea why @ben has it and mine compiles fine without it. Though this goes into the whole forward declaration previously talked about, if the FBlackboardKeySelector type wasn’t known to the header you would have to specify what exactly it is, saying struct FBlackboardKeySelector you tell the header all it needs to know (unless you use any of its members).

Thanks Daniel for explanations. Hopefully @ben would come around to clarify it definitively. It’s a bit different syntax compare to the regular forward declaration that has been used regularly.

Same syntax, just the way that was taught just enables you to use it for the rest of the file.

class Bar;
class Foo
{
    Bar data1;
    Bar data2;
    Bar data3;
};

is the same as doing

class Foo
{
    class Bar data1;
    class Bar data2;
    class Bar data3;
};

Just the latter means you have to type class x2 as much.

1 Like

Thank you again for the detailed explanation. Appreciated!

Thank you so much for writing these thoughtful responses before I go to the thread Dan. @Richard_Yao I can confirm you can rely on @DanM’s explanations.

Only thing left to answer is why you did it when a forward declaration isn’t needed.

Just read through the thread and gotta give thanks to you @DanM! I was a bit confused myself regarding what’s needed for the file path in the #include we’ve been doing. The point you mentioned regarding “references” in the Unreal docs will help a ton! Appreciate it! :smiley:

1 Like

Another reason Dan’s top example of forward declaration is better is that there’s less to go wrong, in the bottom example if you mis-spelt Bar you would get error on compilation rather just a hard to track bug later.

Re why I forward declared, I can’t see where I do in this lecture’s code changes unless I’m being silly?

If you mean why I #include "BehaviorTree/BlackboardComponent.h", this is required for to access the GetValueAsInt() method on the blackboard component.

look at ChooseNextWaypoint.h and how you declared the FBlackboardKeySelector

It’s actually regarding as Dan said, FBlackboardKeySelector.

You have it as struct FBlackboardKeySelector IndexKey

I’m curious if the struct is needed there since both should be independent types correct?

it was probably to help readability.

Privacy & Terms