I have a class called inventory extended from an actorcomponent.
I make the inventory a TSubobjectPtr of my character class and then I initialize it.
characterclass.h
/** Inventory of the Player */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Inventory)
TSubobjectPtr<class UInventory> CharacterInventory;
and .cpp
CharacterInventory = PCIP.CreateDefaultSubobject<UInventory>(this, TEXT("CharacterInventory"));
I got a function in the inventory class that spawns a projectile
Inventory.cpp
void UInventory::FireProjectile(UWorld* World, FVector SpawnLocation, FRotator SpawnRotation)
{
World->SpawnActor<ABaseProjectile>(CurrentProjectile, SpawnLocation, SpawnRotation);
}
The CurrentProjectile is a blueprint class initialized in blueprints of the character class.
The function called FireProjectile is called by the Character class in c++
characterclass.cpp
const FVector SpawnLocation = Mesh1P->GetSocketLocation("firestartloc");
FVector Angle = (HitLocation - SpawnLocation);
FRotator SpawnRotation = Angle.Rotation();
UWorld* const World = GetWorld();
CharacterInventory->FireProjectile(World ,Angle, SpawnRotation);
This does spawn the projectile in game. As seen from the sceneoutliner but, that projectile is neither visible to me nor does it interact with anything else or hits.
But, if I spawn projectile directly form the characterclass something like this
const FVector SpawnLocation = Mesh1P->GetSocketLocation("firestartloc");
FVector Angle = (HitLocation - SpawnLocation);
FRotator SpawnRotation = Angle.Rotation();
UWorld* const World = GetWorld();
World->SpawnActor<ABaseProjectile>(CharacterInventory->CurrentProjectile, SpawnLocation, SpawnRotation);
This spawns and the projectiles are visible and hit objects.