I know this isn’t a very technically correct solution but you could move those references to somewhere else like the playercontroller or gamemode, you could get references to those quite easily from any object ingame.
In one of my classes, I hold a few class pointers to blueprints in my game. I use the following code to do so:
.h
TSubclassOf<class AItem> BlueprintChair;
TSubclassOf<class AItem> BlueprintLamp;
.cpp (In the constructor)
static ConstructorHelpers::FObjectFinder<UBlueprint> ChairBlueprint(TEXT("Blueprint'/Game/Item/Chair.Chair'"));
if (ChairBlueprint.Object)
BlueprintChair = (UClass*)ChairBlueprint.Object->GeneratedClass;
static ConstructorHelpers::FObjectFinder<UBlueprint> LampBlueprint(TEXT("Blueprint'/Game/Item/Lamp.Lamp'"));
if (LampBlueprint.Object)
BlueprintLamp = (UClass*)LampBlueprint.Object->GeneratedClass;
The code works fine, but the issue becomes overhead. Every time the class is instanced, it will carry overhead for the two TSubclassOf<>. If there was only a few of these objects, that would be okay, but my game has thousands of instances making it unnecessary overhead. Is it possible to make the two TSubclassOf<> static objects, and if so, how would I go about doing so? I can’t initialize them as I normally would with static objects because they need to be set in the constructor since I use ConsructorHelpers.
I created my own level info actor and place level specific details there for any object to reference inside levels.
While that is a potential way of doing it, it wouldn’t work in my case because I can’t pass a reference to procedurally spawning item when it’s another item.
Hmmm I don’t understand why it wouldn’t work, even in that case. Instead of passing the reference to the item as its spawning why not let the spawning item attempt to get those references.