Latest news

Unreal C++, Search your way through the web.

In this blog post, we will see something that may seem obvious, but the more I work with people, the more I realize it’s not!

Let’s follow the journey on how to find information over the web.

Try not to reinvent the wheel

It’s easy to forget that unlike Unity, Unreal is packed with tons of features that are easy to overlook, and sometimes we tend to reinvent the wheel simply because we don’t know a feature exists.

In this case, I was looking for some information about the Sweep feature within the SetActorLocation, especially how the SweepHitResult is used.

We’ll use that as an excuse to dive into how to search the web…

The Source code

When I start to look for C++ code information, I always start using the source code of Unreal Engine. Epic provides full access to it, so it’s always a nice insight to dig in the source code, and that for few reasons;

First step, see how it’s implemented; Sometimes some stuff may seem harmless and simply looking at the code can give a nice insight and how heavy a function might be.

Also, most of the source code contains a lot of comments, and you can find extra information by untangling sub-elements within the function itself

If this is not giving enough information, I’ll try to look if the function itself was implemented within the source code.

Unfortunately, in this case, I can only find the basic implementation. None of the code is using the SweepHitResult.

The next step: the Unreal Engine online documentation, You never know. It might be filled with info.

The documentation is the same as the source-code.

No luck here, So to figure out how to implement it, so I’ve started to look for examples of code and how it’s supposed to be implemented within Google.

But the SetActorLocation is so widely used with its basic form, that it becomes quite a challenge to find anything mentioning another way of using the function.

Another issue is that most of the questions and threads in forums are Blueprint related.

The Power of Github

Usually when I can’t find the way a function is implemented in C++ within google or Unreal Source code; I’ll start digging in Github.

But a quick search is not enough, most of the time you will end-up by finding people who forked the Source code of Unreal

Digging Deeper with advanced search

Using advanced filters to exclude common files and file extension is a good way to filter as much as you can, and you will most likely find what you want.

by using the keyword “NOT” in Github, you can make sure to filter as much as you can and goes from almost 80k result to less than 10 results; it will be much more manageable to see how it’s implemented.

Now with that quick search over the web, we know how we can implement the SweepHitResult:

FVector Location = this->GetActorLocation();
FHitResult OutSweepHitResult;

Actor->SetActorLocation(Location, true, &OutSweepHitResult);

if(OutSweepHitResult.IsValidBlockingHit()) {
     // It collided with something...

I hope this was helpful 🙂

exiinUnreal C++, Search your way through the web.