Bug. Actorcomponent can spawn actors but those actors are not visible

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.

Hi ,

I tried to reproduce this issue, but only had partial success. I was able to get the projectile to spawn as you mentioned by spawning from the Character class. However, when I tried to spawn a projectile from the Inventory class, nothing happened at all. I did not even have anything added to the Scene Outliner. I did have to make a few alterations to the code you provided in order to get it to build, though.

Could you provide some additional information?

  • What version of the Engine are you using, and are you using the binary version or did you build the Engine from source code?
  • Does this only happen in your project, or can you reproduce it in a new project from one of the templates?
  • How do you identify CurrentProjectile in the Inventory class since it is originally set in the Character class?
  • Where and how do you declare HitLocation in the Character class?
  • Do you include the header file for ABaseProjectile in your Inventory class?

Any additional information you can provide would be very helpful.

Hi ,

We have not heard back from you in a few days, so we are marking this post as Resolved for tracking purposes. If you are still experiencing the issue you reported, please respond to this message with additional information and we will offer further assistance.

Thank you.

Yes the problem was solved. It not related to any engine issue. I had some error in the projectile location where it was generated.