In the last section, we were tought that is was important to protect our pointers. This included initialising all pointers to nullptr, logging errors if the pointers were still nullptr after being set in the .cpp code, and then including an a line saying if (!SomePointer) {return;} before any pointer that is being used in the code.
In this section, none of that is being done, and it hasn’t been mentioned if this is just an oversite, and we should do it as an extention excercise, or if we don’t need to protect the pointers because they all being used to create the class.
Should I be initalising all pointers in the PawnBase.h file to nullptr, and put a if statement before the uses of the pointers, e.g.
BaseMesh = CreateDefaultSubobject(TEXT(“Base Mesh”));
if (!BaseMesh)
{
UE_LOG(LogTemp, Error, TEXT("No BaseMesh found));
return;
}
BaseMesh->SetupAttachment(RootComponent);
Is it worth doing this as an extention excercise, or is protecting the pointers not needed here?
EDIT: As I went through later lectures, I noticed some pointers are protected using the if-return statement. I also realised that most of my questions about protecting pointers are in regards to components, which are initalised during compile time, rather than at run time (as I think I understand). So does that mean component pointers don’t need the same protection as other pointers?