Skip to content

Thad writes blogs

this is a lot more work than i expected

Menu
  • About
  • Pin Posts
Menu

Advent of Code in Unreal Engine Day 3

Posted on December 3, 2022December 3, 2022 by Thad

In Day 3 we are searching substrings for character matches. It is a Saturday morning, and I want to get this finished before I go about my day, so my first step is to write some C++:

// In AoC22BPFunctionLibrary.h
UFUNCTION(BlueprintCallable)
static TArray<int> D03_CountCharacters(const FString& TextIn);	

// In AoC22BPFunctionLibrary.cpp
TArray<int> UAoC22BPFunctionLibrary::D03_CountCharacters(const FString& TextIn)
{
	TArray<int> Result;
	Result.SetNum(53);
	for(auto c : TextIn)
	{
		if (c >= 'a' && c <='z')
		{
			c = 1 + (c - 'a');
		}
		else if (c >= 'A' && c <='Z')
		{
			c = 27 + (c - 'A');
		}
		ensure(c>=1 && c<=52);
		Result[c]++;
	}
	return Result;
}	

This converts the letters into the elves priority system, and counts how many of each priority in a string. This is the foundation for everything else, and would be, let us just say inelegant in Blueprint.

Using this we can solve part 1 line by line:

https://blueprintue.com/blueprint/uf1s6bc3/

And part 2 in a similar fashion:

https://blueprintue.com/blueprint/d3b4i_ua/

Was it cheating to write some of this in C++? Perhaps. I appreciate that for a lot of people Unreal is Blueprint only, and going to C++ is not an option, but for programmers, knowing when to use Blueprint and when you should write some support code in C++ is an important part of Being Good at Unreal.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Archives

  • October 2024
  • January 2023
  • December 2022
  • November 2022

Categories

  • Food
  • meta
  • Uncategorized
© 2025 Thad writes blogs | Powered by Minimalist Blog WordPress Theme