I'm new to programming and game development in general every time I read and hear that pointers are a nightmare I want to ask if it is necessary to check pointers in such cases as shown below?
// create a component of a certain type and return a pointer to data of this type
StaticMeshCompt = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("StaticMesh"));
if (StaticMeshCompt)
{
// further work with the component
}
No, there's no need to check the pointer. The cases where CreateDefaultSubobject
could return nullptr
are :
nullptr
(It's guaranteed to be valid for any UObject
).UStaticMeshComponent
).