Download

Spawned Actors have no collision

Hiya!

Ive been having some trouble recently trying to spawn actors that collide correctly.

The Actor in question:



# TileCollisionActor.h


UCLASS()
class TRANSPORTALA_API ATileCollisionActor : public AActor
{
    GENERATED_BODY()

public:    
    // Sets default values for this actor's properties
    ATileCollisionActor();

    UPROPERTY(EditAnywhere)
    UBoxComponent* Collider;

    // Unfortunately you cant store an exposed pointer
    // to a FStruct type, so we'll store the index of the associated
    // tile here, its a bit more flaky but should do the job.
    UPROPERTY()
    int32 TileIndex;

protected:
    // Called when the game starts or when spawned
    virtual void BeginPlay() override;
};

# TileCollisionActor.cpp

#include "TileCollisionActor.h"

// Sets default values
ATileCollisionActor::ATileCollisionActor()
{
    Collider = CreateDefaultSubobject<UBoxComponent>(TEXT("Collider"));
    RootComponent = Collider;
    Collider->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
    // These settings just kinda work for our gubbins.
    Collider->SetRelativeScale3D(FVector(0.77f, 0.77f, 0.5f));
    //Collider->SetCollisionObjectType(ECollisionChannel::);
    //Collider->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Block);
    //Collider->SetCollisionResponseToChannel(ECollisionChannel::ECC_GameTraceChannel1, ECollisionResponse::ECR_Block);
}

// Called when the game starts or when spawned
void ATileCollisionActor::BeginPlay()
{
    Super::BeginPlay();
}


Im spawning these actors enmasse from another, like so:



# SomeTileSpawner.h

*snip*
    UPROPERTY(EditAnywhere, BlueprintReadWrite)
    TSubclassOf<class ATileCollisionActor> TileBP;
*snip*

# SomeTileSpawner.cpp
.. stuff
auto col = GetWorld()->SpawnActor<ATileCollisionActor>(TileBP->GetAuthoritativeClass(), _state.Tiles[index].Location, FRotator::ZeroRotator);


(I assign a blueprint with the tile to this variable to eliminate issues with misconfiguration, the blueprint when placed directly in the world collides correctly.)
The blueprint is assigned to block all collisions

Im raycasting from my controller using
GetHitResultUnderCursor(ECollisionChannel::ECC_WorldStatic , false, SomeHit);

However, it never collides with the spawned actors, only with versions that i place directly into the world.

I guess my question is 2 fold:
Is there some further steps to component initialization that I am missing?
Or more broadly, why do spawned versions of this actor have no collision properties

I can see the colliders in the editor via the Visibility and PlayerCollision views.

Thanks for your time! :slight_smile:

Hiya again!

So the problem here was one of replication, these were being conditionally spawned, and in some cases the authoriative client would never run the spawning code. Once I fixed that, or used a dedicated server instead of a listen server, then it works as intended,

Thanks!