TIL: Learn to Code in C++ by Developing Your First Game (Section 3, Lectures 57-58)

It’s oddly satisfying to get some C++ working and see a connection with UE4, even if it’s as minor as printing a Warning message in the output. At least I can rest assured that all the perforce set-up I’ve done is working.

Section: 3 – Building Escape – Your First Unreal / C++ Game

Lecture 57: Runtime Messages for Feedback

-Using UE_LOG to print to the output Console
-https://wiki.unrealengine.com/Logs,_Printing_Messages_To_Yourself_During_Runtime#Related_Tutorial

FindClassOne thing to keep in mind, is that when working with assets in the world outliner, you can typically select an object and press ctrl + b to find it in the content browser. Typically, parameters on the object will have a little magnifying glass allowing you to further select things that are connected into an object. This isn’t true for components though. If we want to easily find a component/module in the content browser, we need to right click it, and then select the option to find it in the content browser. Once you have found the module, you can double click it to open it in Visual Studio.

Because I’m using Perforce, version control is a little different for me than what’s in the video tutorials. Perforce doesn’t just have version control, it also has a check-in check-out system which is designed to prevent multiple people from working on a file at once. While it would be possible for me to check files in and out directly using Perforce, it’s a little bit clumsy doing it this way. This is why I connect using the source control menu directly in UE which allows me to handle check-outs directly in UE.

UE doesn’t however give me the option to check-out the Position Report module that I’ve created. I’m assuming it doesn’t allow me to deal with source control of any of the c++ modules. So I need to make sure that I handle that in Visual Studio if I want a clean workflow. This means using the VSIX plug-in (PSVS User Guide can be found in the More Info menu beneath the plug-in’s download link. Or directly here.)

Once it’s installed, restart VS if necessary then go to Tools->Options->Source Control to enable the plug-in. The File->Open Connection to a Perforce Depot. Then it’s a matter of entering in the server, login name, and work space in order to start checking files out directly through Visual Studio. Once you’re connected, you should see in the Solution Explorer, that if you right click a file you have the ability to Check it Out.

My preferred workflow is check out through UE and VS as I need to, and then when I’m done working, check everything in at once through Perforce.

Once everything is ready to go, I change line 24 to read:
UE_LOG(LogTemp, Warning, TEXT("Position report reporting for duty!"));

You now need to save the file and either build the code in VS, or Compile in UE. Total build time for me in VS was Total build time: 48.93 seconds. Yikes. This seems like it’s going to be slow going if I need to build frequently.

Once built, you should be able to return to UE, go to Windows->Developer Tools->Output Log, and when you start the game, you should see your message play just as in this blog post’s Featured Image.

Lecture 58: Accessing Object Names

    -Use GetOwner() to gind the component’s owner
    -*AActor is a pointer to an actor
    – Use “->” to access methods through pointers
    – Use Getname() to find the object’s name
    – Use %s as a format operator for strings
    – Use * to “dereference” pointers

-AActor is part of the Actor class, which is why it’s prefaced with an A.
-* means that it’s a pointer (the memory address).
-“.” doesn’t allow us to get the properties from pointers, instead we use “->”

We can type the line:
FString ObjectName = GetOwner()->GetName();
to create our ObjectName, however we can’t place it directly into the UE_LOG as is. We need to Log an FString.

UE_LOG(LogTemp, Warning, TEXT("Position report reporting for duty!"));
becomes:
UE_LOG(LogTemp, Warning, TEXT("Position report reporting for %s"), *ObjectName);