Announcement

Collapse
No announcement yet.

Actor spawned through an actor component are not visible in game nor they interact

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Actor spawned through an actor component are not visible in game nor they interact

    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

    Code:
    	/** Inventory of the Player */
    	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Inventory)
    		TSubobjectPtr<class UInventory> CharacterInventory;
    and .cpp

    Code:
    	CharacterInventory = PCIP.CreateDefaultSubobject<UInventory>(this, TEXT("CharacterInventory"));
    I got a function in the inventory class that spawns a projectile

    Inventory.cpp

    Code:
    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

    Code:
    	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

    Code:
    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.

    Related abswerhub links https://answers.unrealengine.com/que...those-act.html
    Last edited by envenger; 08-11-2014, 10:15 AM.
Working...
X