Utility plugin providing a set of functionalities for easily spawning actors on navmeshes.
All publicly accessible functions and data are marked with the NavSpawn category, ensuring that everything related to the plugin can be found in one place when using blueprint editing tools.
The plugin also includes its own set of developer settings, which can be accessed by navigating to Project Settings and searching for "Nav Spawn Settings". These allow you to change some of the core features of the plugin e.g. (MaxRejectionSamplingAttempts, DebugShapeThickness, DebugShapeLifetime...). Go here to find out more.
This section will cover and explain in detail the full range of custom developer settings available in the plugin.
int MaxRejectionSamplingAttempts;
Determines the maximum number of iterations that a function can take to find a suitable location. Lower values can increase performance; however, it is increasingly likely that a suitable location cannot be found, depending on the data specified. Therefore, a good balance for this value should be determined (Default value is 25).
int CircleSegments;
Determines how many segments the debug circles should be made up of.
float DebugShapeThickness;
Determines how thick the lines used to draw the debug shapes should be.
float DebugShapeLifetime;
Determines how long the drawn debug shapes should remain active before disappearing.
uint8 DepthPriority;
Determines the drawing priority of the debug shapes; the default priority is set to draw over all rendered items to ensure maximum visibility.
bool bShouldDrawAxis;
Determines whether the debug circles should be drawn with lines going through them, marking their X and Y axis.
bool bShouldLinesPersist;
Determines whether the drawn debug shapes should ignore the set lifetime and instead remain visible for the duration of the application.
This section will cover and explain in detail the full range of spawning functions available to both C++ and Blueprint users of the plugin.
Showcase Setup
Spawns the actor in a random location on the navmesh.
template<class T>
static T* SpawnActorRandom(UObject* WorldContextObject, const FSpawnInfo& SpawnInfo = FSpawnInfo(),
const FActorSpawnParameters& SpawnParameters = FActorSpawnParameters(),
ANavigationData* NavData = nullptr, const FSharedConstNavQueryFilter QueryFilter = nullptr);
WorldContextObject - The object from which a safe reference to UWorld can be retrieved. Typically, you would pass 'this' when calling from a class deriving from AActor.
SpawnInfo - Holds optional data for customising how you want your actor to be spawned e.g. (SpawnOffset, Rotation...). Go here to find out more.
SpawnParameters - Provides forward compatibility with existing UWorld SpawnActor calls. Allows you to specify additional spawning data e.g. (Name, Owner, Instigator...).
NavData - Provides forward compatibility with existing UNavigationSystemV1 function calls. Allows you to specify which navigation data you want to query for a location.
QueryFilter - Provides forward compatibility with existing UNavigationSystemV1 function calls. Allows you to filter out certain parts of the queried navmesh.
Returns a pointer to the spawned actor or nullptr if the actor couldn't be spawned.
Example
Where AActor refers to your own custom AActor derived class.
UNavSpawn::SpawnActorRandom<AActor>(this);
// Optionally
if (AActor* SpawnedActor = UNavSpawn::SpawnActorRandom<AActor>(this))
{
// Code that utilizes the spawned actor here...
}
ActorClass - The specific type of AActor derived class that you want spawned.
SpawnInfo - Holds optional data for customising how you want your actor to be spawned e.g. (SpawnOffset, Rotation...). Go here to find out more.
CollisionHandlingMethod - The way in which to handle the spawning of an actor in cases where the chosen location causes it to penetrate blocking collisions.
TransformScaleMethod - The way in which the provided scale and the actor's default object scale interact.
Owner - Sets the spawned actor's owner to the provided owner.
Instigator - Sets the spawned actor's instigator to the provided instigator.
NavData - Provides forward compatibility with existing UNavigationSystemV1 function calls. Allows you to specify which navigation data you want to query for a location.
FilterClass - Provides forward compatibility with existing UNavigationSystemV1 function calls. Allows you to filter out certain parts of the queried navmesh by retrieving the QueryFilter from the specified FilterClass.
Returns an Actor Object Reference to the spawned actor; if the actor couldn't be spawned, the reference will be None.
Spawns the actor in a random location on the navmesh within a circular area defined by the specified radius, centered around the origin location.
template<class T>
static T* SpawnActorRandomInRadius(UObject* WorldContextObject, const FFindLocationInfo& FindLocationInfo,
const FSpawnInfo& SpawnInfo = FSpawnInfo(), const FActorSpawnParameters& SpawnParameters = FActorSpawnParameters(), const bool bDrawDebugShape = false, ANavigationData* NavData = nullptr, const FSharedConstNavQueryFilter QueryFilter = nullptr);
WorldContextObject - The object from which a safe reference to UWorld can be retrieved. Typically, you would pass 'this' when calling from a class deriving from AActor.
FindLocationInfo - Holds necessary data used by the navigation system to find an acceptable random location e.g. (Origin, Radius...). Go here to find out more.
SpawnInfo - Holds optional data for customising how you want your actor to be spawned e.g. (SpawnOffset, Rotation...). Go here to find out more.
SpawnParameters - Provides forward compatibility with existing UWorld SpawnActor calls. Allows you to specify additional spawning data e.g. (Name, Owner, Instigator...).
bDrawDebugShape - When enabled, draws a debug circle using the provided FindLocationInfo to visualise the search area for possible spawn locations.
NavData - Provides forward compatibility with existing UNavigationSystemV1 function calls. Allows you to specify which navigation data you want to query for a location.
QueryFilter - Provides forward compatibility with existing UNavigationSystemV1 function calls. Allows you to filter out certain parts of the queried navmesh.
Returns a pointer to the spawned actor or nullptr if the actor couldn't be spawned.
Example
Where AActor refers to your own custom AActor derived class.
FFindLocationInfo LocationInfo;
LocationInfo.Origin = GetActorLocation();
LocationInfo.Radius = 500.0f;
UNavSpawn::SpawnActorRandomInRadius<AActor>(this, LocationInfo, FSpawnInfo(), FActorSpawnParameters(), true);
// Optionally
if (AActor* SpawnedActor = UNavSpawn::SpawnActorRandomInRadius<AActor>(this, LocationInfo, FSpawnInfo(), FActorSpawnParameters(), true))
{
// Code that utilizes the spawned actor here...
}
ActorClass - The specific type of AActor derived class that you want spawned.
FindLocationInfo - Holds necessary data used by the navigation system to find an acceptable random location e.g. (Origin, Radius...). Go here to find out more.
SpawnInfo - Holds optional data for customising how you want your actor to be spawned e.g. (SpawnOffset, Rotation...). Go here to find out more.
CollisionHandlingMethod - The way in which to handle the spawning of an actor in cases where the chosen location causes it to penetrate blocking collisions.
TransformScaleMethod - The way in which the provided scale and the actor's default object scale interact.
Owner - Sets the spawned actor's owner to the provided owner.
Instigator - Sets the spawned actor's instigator to the provided instigator.
DrawDebugShape - When enabled, draws a debug circle using the provided FindLocationInfo to visualise the search area for possible spawn locations.
NavData - Provides forward compatibility with existing UNavigationSystemV1 function calls. Allows you to specify which navigation data you want to query for a location.
FilterClass - Provides forward compatibility with existing UNavigationSystemV1 function calls. Allows you to filter out certain parts of the queried navmesh by retrieving the QueryFilter from the specified FilterClass.
Returns an Actor Object Reference to the spawned actor; if the actor couldn't be spawned, the reference will be None.
Spawns the actor in a random location on the navmesh within an annular region (a ring) defined by the inner and outer radii, centered around the origin location.
Remarks
If a valid OuterRadius is not provided by the user, the OuterRadius will be set using the value held in the InnerRadius plus some arbitrary amount.
template<class T>
static T* SpawnActorRandomBetweenRadii(UObject* WorldContextObject, const FFindLocationInfo& FindLocationInfo,
const FSpawnInfo& SpawnInfo = FSpawnInfo(), const FActorSpawnParameters& SpawnParameters = FActorSpawnParameters(), const bool bDrawDebugShape = false, ANavigationData* NavData = nullptr, const FSharedConstNavQueryFilter QueryFilter = nullptr);
WorldContextObject - The object from which a safe reference to UWorld can be retrieved. Typically, you would pass 'this' when calling from a class deriving from AActor.
FindLocationInfo - Holds necessary data used by the navigation system to find an acceptable random location e.g. (Origin, Radius...). Go here to find out more.
SpawnInfo - Holds optional data for customising how you want your actor to be spawned e.g. (SpawnOffset, Rotation...). Go here to find out more.
SpawnParameters - Provides forward compatibility with existing UWorld SpawnActor calls. Allows you to specify additional spawning data e.g. (Name, Owner, Instigator...).
bDrawDebugShape - When enabled, draws a debug circle using the provided FindLocationInfo to visualise the search area for possible spawn locations.
NavData - Provides forward compatibility with existing UNavigationSystemV1 function calls. Allows you to specify which navigation data you want to query for a location.
QueryFilter - Provides forward compatibility with existing UNavigationSystemV1 function calls. Allows you to filter out certain parts of the queried navmesh.
Returns a pointer to the spawned actor or nullptr if the actor couldn't be spawned.
Example
Where AActor refers to your own custom AActor derived class.
FFindLocationInfo LocationInfo;
LocationInfo.Origin = GetActorLocation();
LocationInfo.Radius = 500.0f; // INFO: Acts as the InnerRadius
LocationInfo.OuterRadius = 1000.0f;
UNavSpawn::SpawnActorRandomBetweenRadii<AActor>(this, LocationInfo, FSpawnInfo(), FActorSpawnParameters(), true);
// Optionally
if (AActor* SpawnedActor = UNavSpawn::SpawnActorRandomBetweenRadii<AActor>(this, LocationInfo, FSpawnInfo(), FActorSpawnParameters(), true))
{
// Code that utilizes the spawned actor here...
}
ActorClass - The specific type of AActor derived class that you want spawned.
FindLocationInfo - Holds necessary data used by the navigation system to find an acceptable random location e.g. (Origin, Radius...). Go here to find out more.
SpawnInfo - Holds optional data for customising how you want your actor to be spawned e.g. (SpawnOffset, Rotation...). Go here to find out more.
CollisionHandlingMethod - The way in which to handle the spawning of an actor in cases where the chosen location causes it to penetrate blocking collisions.
TransformScaleMethod - The way in which the provided scale and the actor's default object scale interact.
Owner - Sets the spawned actor's owner to the provided owner.
Instigator - Sets the spawned actor's instigator to the provided instigator.
DrawDebugShape - When enabled, draws a debug circle using the provided FindLocationInfo to visualise the search area for possible spawn locations.
NavData - Provides forward compatibility with existing UNavigationSystemV1 function calls. Allows you to specify which navigation data you want to query for a location.
FilterClass - Provides forward compatibility with existing UNavigationSystemV1 function calls. Allows you to filter out certain parts of the queried navmesh by retrieving the QueryFilter from the specified FilterClass.
Returns an Actor Object Reference to the spawned actor; if the actor couldn't be spawned, the reference will be None.
This section will cover and explain in detail the full range of helper functions available to both C++ and Blueprint users of the plugin.
Finds a random location on the navmesh.
static bool FindRandomLocation(const UObject* WorldContextObject, FVector& SpawnLocation, ANavigationData* NavData = nullptr, const FSharedConstNavQueryFilter& QueryFilter = nullptr);
WorldContextObject - The object from which a safe reference to UWorld can be retrieved. Typically, you would pass 'this' when calling from a class deriving from AActor.
SpawnLocation - Holds the resulting random position on the navmesh where an actor can be spawned, granted the function returns true (Success).
NavData - Provides forward compatibility with existing UNavigationSystemV1 function calls. Allows you to specify which navigation data you want to query for a location.
QueryFilter - Provides forward compatibility with existing UNavigationSystemV1 function calls. Allows you to filter out certain parts of the queried navmesh.
Returns true upon finding a valid location; otherwise, returns false if no suitable location could be determined.
Example
FVector FoundLocation;
if (UNavSpawn::FindRandomLocation(this, FoundLocation))
{
// Code that utilizes the found location here...
}
NavData - Provides forward compatibility with existing UNavigationSystemV1 function calls. Allows you to specify which navigation data you want to query for a location.
FilterClass - Provides forward compatibility with existing UNavigationSystemV1 function calls. Allows you to filter out certain parts of the queried navmesh by retrieving the QueryFilter from the specified FilterClass.
Returns true upon successfully finding a valid location along with the location itself; otherwise, returns false if no suitable location could be determined along with a default zero vector.
Finds a random location on the navmesh within the specified radius from the origin.
static bool FindRandomLocationInRadius(const UObject* WorldContextObject, const FFindLocationInfo& FindLocationInfo, FVector& SpawnLocation, ANavigationData* NavData = nullptr, const FSharedConstNavQueryFilter& QueryFilter = nullptr);
WorldContextObject - The object from which a safe reference to UWorld can be retrieved. Typically, you would pass 'this' when calling from a class deriving from AActor.
FindLocationInfo - Holds necessary data used by the navigation system to find an acceptable random location e.g. (Origin, Radius...). Go here to find out more.
SpawnLocation - Holds the resulting random position on the navmesh where an actor can be spawned, granted the function returns true (Success).
NavData - Provides forward compatibility with existing UNavigationSystemV1 function calls. Allows you to specify which navigation data you want to query for a location.
QueryFilter - Provides forward compatibility with existing UNavigationSystemV1 function calls. Allows you to filter out certain parts of the queried navmesh.
Returns true upon finding a valid location; otherwise, returns false if no suitable location could be determined.
Example
FFindLocationInfo LocationInfo;
LocationInfo.Origin = GetActorLocation();
LocationInfo.Radius = 500.0f;
FVector FoundLocation;
if (UNavSpawn::FindRandomLocationInRadius(this, LocationInfo, FoundLocation))
{
// Code that utilizes the found location here...
}
FindLocationInfo - Holds necessary data used by the navigation system to find an acceptable random location e.g. (Origin, Radius...). Go here to find out more.
NavData - Provides forward compatibility with existing UNavigationSystemV1 function calls. Allows you to specify which navigation data you want to query for a location.
FilterClass - Provides forward compatibility with existing UNavigationSystemV1 function calls. Allows you to filter out certain parts of the queried navmesh by retrieving the QueryFilter from the specified FilterClass.
Returns true upon successfully finding a valid location along with the location itself; otherwise, returns false if no suitable location could be determined along with a default zero vector.
Finds a random location on the navmesh between the specified inner and outer radii from the origin.
static bool FindRandomLocationBetweenRadii(const UObject* WorldContextObject, const FFindLocationInfo& FindLocationInfo, FVector& SpawnLocation, ANavigationData* NavData = nullptr, const FSharedConstNavQueryFilter& QueryFilter = nullptr);
WorldContextObject - The object from which a safe reference to UWorld can be retrieved. Typically, you would pass 'this' when calling from a class deriving from AActor.
FindLocationInfo - Holds necessary data used by the navigation system to find an acceptable random location e.g. (Origin, Radius...). Go here to find out more.
SpawnLocation - Holds the resulting random position on the navmesh where an actor can be spawned, granted the function returns true (Success).
NavData - Provides forward compatibility with existing UNavigationSystemV1 function calls. Allows you to specify which navigation data you want to query for a location.
QueryFilter - Provides forward compatibility with existing UNavigationSystemV1 function calls. Allows you to filter out certain parts of the queried navmesh.
Returns true upon finding a valid location; otherwise, returns false if no suitable location could be determined.
Example
FFindLocationInfo LocationInfo;
LocationInfo.Origin = GetActorLocation();
LocationInfo.Radius = 500.0f; // INFO: Acts as the InnerRadius
LocationInfo.OuterRadius = 1000.0f;
FVector FoundLocation;
if (UNavSpawn::FindRandomLocationInRadius(this, LocationInfo, FoundLocation))
{
// Code that utilizes the found location here...
}
FindLocationInfo - Holds necessary data used by the navigation system to find an acceptable random location e.g. (Origin, Radius...). Go here to find out more.
NavData - Provides forward compatibility with existing UNavigationSystemV1 function calls. Allows you to specify which navigation data you want to query for a location.
FilterClass - Provides forward compatibility with existing UNavigationSystemV1 function calls. Allows you to filter out certain parts of the queried navmesh by retrieving the QueryFilter from the specified FilterClass.
Returns true upon successfully finding a valid location along with the location itself; otherwise, returns false if no suitable location could be determined along with a default zero vector.
Determines whether the chosen location and/or bounds component are outside of the primary camera's view frustum.
Remarks
If a valid BoundsComponent is not provided, the function will only test visibility against the provided location; otherwise, it will test visibility against both the location and the provided bounds component projected onto the specified location in an Axis-Aligned manner.
static bool IsLocationOutOfView(UObject* WorldContextObject, const FVector& Location, const UNavSpawnBoundsComponent* BoundsComponent);
WorldContextObject - The object from which a safe reference to UWorld can be retrieved. Typically, you would pass 'this' when calling from a class deriving from AActor.
Location - The location we are testing visibility against.
BoundsComponent - The UNavSpawnBoundsComponent we are testing visibility against. Go here to find out more.
Returns true if the location isn't visible and no bounds component has been provided, also returns true if a valid bounds component has been provided and neither the location nor bounds component is visible by the primary camera, otherwise returns false.
Example
// Constructor
BoundsComponent = CreateDefaultSubobject<UNavSpawnBoundsComponent>(TEXT("BoundsComponent"));
BoundsComponent->SetupAttachment(RootComponent);
const FVector HalfExtents = FVector(50.0f, 50.0f, 50.0f);
BoundsComponent->SetBoxHalfExtents(HalfExtents);
// During Gameplay
if (UNavSpawn::IsLocationOutOfView(this, GetActorLocation(), BoundsComponent))
{
// Code to perform if the chosen location and provided bounds component aren't visible by the primary camera
}
Location - The location we are testing visibility against.
BoundsComponent - The UNavSpawnBoundsComponent we are testing visibility against. Go here to find out more.
Returns true if the location isn't visible and no bounds component has been provided, also returns true if a valid bounds component has been provided and neither the location nor bounds component is visible by the primary camera, otherwise returns false.
This section will cover and explain in detail all the data containers used by the plugin.
Holds necessary data used by the navigation system to find an acceptable random location.
FVector Origin;
Refers to the location in world space from which navmesh queries will be carried out. If calling from an actor, you'd typically pass in the result from GetActorLocation.
float Radius;
Used to specify the search range in a circular region on the navmesh for 'InRadius' style functions; otherwise, in the case of 'BetweenRadii' style functions, it marks the inner circular region that is to be avoided by the search.
float OuterRadius;
Used in conjunction with the Radius value (Referred to as InnerRadius in this case) to specify an annular (ring) search region. As a warning, setting an OuterRadius value that is less than or equal to Radius creates an invalid OuterRadius that will naturally be corrected by 'BetweenRadii' style functions.
Holds optional data for customizing how you want your actor to be spawned.
FVector SpawnOffset;
Used to specify custom offset amounts. The chosen location will be offset by this value, making it the new spawn location for the actor. A good example of its use could be to offset actors by their Z-Axis to spawn them above the navmesh. As a warning, since this is a user customisation, the applied offset isn't passed through any further checks to ensure the adjusted location remains on the navmesh.
FRotator Rotation;
Provides forward compatibility with existing UWorld SpawnActor calls. Allows you to specify the rotation of your actor when it is spawned in.
bool bRequireOutOfView;
When set to true, enables primary camera visibility checks in 'SpawnActor' style function calls. Can be used purely to check whether the chosen location is visible; however, this won't cover the actor's visible features, therefore it should be used in conjunction with a UNavSpawnBoundsComponent. Go here to find out more.
This section will cover and explain in detail all the components used by the plugin.
Used to define the owning actor's maximum visual bounds, to ensure the actor can properly be tested against the primary camera's visibility.
Remarks
Only one NavSpawnBoundsComponent is designed to be on any given actor that wishes to take part in visibility checks.
The component does not come with capabilities to rotate, as visibility detection logic is carried out using FConvexVolumes, which perform Axis-Aligned checks.
In its current state, the component also doesn't come with capabilities to be scaled or moved around in the blueprint editor. This is mainly done to keep the logic regarding visibility checks simpler and more concise.
The component comes with a ComponentVisualizer held in an editor-only module (NavigationSpawnEditor), which should aid in the ability to adjust NavSpawnBounds to fully encompass your actors' visual elements.
The ENavSpawnBoundsShape defines two possible shapes that a NavSpawnBoundsComponent can take (Box, Sphere), use whichever shape fits your actor's visual constraints more.
ENavSpawnBoundsShape BoundsShape;
Used to specify the data that will be used in visibility calculations. If Box is selected, it will access the component's BoxHalfExtents; otherwise, if Sphere is selected, it will access the component's Radius. If None is selected, no visibility checks can be carried out, and you will be notified with a log warning.
FVector BoxHalfExtents;
Stores the half extent values specified by the user, which will be used in visibility checks if Box is selected as the BoundsShape. This value will be hidden in the details panel if Box is not selected.
float Radius;
Stores the radius value specified by the user, which will be used in visibility checks if Sphere is selected as the BoundsShape. This value will be hidden in the details panel if Sphere is not selected.