Help with Spawn System

Hello all! My brain is completely dead today and I need to get this part of my game working. So what I currently have is two classes: ABSpawnMode and ABGameMode. In blueprints derived from ABGameMode, I handle the completion of tasks and such. I have a blueprint derived from ABGameMode in which I handle the spawning of characters after a task is completed. It contains an array of FABEnemyInformation, a struct I created to hold information about spawning enemies. This struct is setup like this:



UENUM(BlueprintType)
namespace ESpawnModeRestriction
{
	enum ESMR_Restriction
	{
		ESMR_Anywhere UMETA(DisplayName = "Anywhere"),
		ESMR_OnlyInside UMETA(DisplayName = "Only Inside"),
		ESMR_OnlyOutside UMETA(DisplayName = "Only Outside"),
	};
}

/**
 * 
 */
USTRUCT(BlueprintType)
struct ABRUPT_API FABEntityInformation
{
	GENERATED_USTRUCT_BODY()

	public:
		/* Class this entity spawns. */
		UPROPERTY(EditAnywhere, Category = "Entity Information")
		TSubclassOf<AActor> Class;

		/* What are this entity's spawn restrictions? */
		UPROPERTY(EditAnywhere, Category = "Entity Information")
		TEnumAsByte<ESpawnModeRestriction::ESMR_Restriction> SpawnRestriction;

		FABEntityInformation::FABEntityInformation()
		{
			// Set Defaults.
			SpawnRestriction = ESpawnModeRestriction::ESMR_Anywhere;
		}
};


This struct contains the type of enemy I want to spawn, and their spawn restrictions. I can choose whether this particular enemy can spawn anywhere, inside only, or outside only.

In blueprints derived from ABSpawnMode, I can override a FTransform function called “CalculateSpawnTransform”. ABSpawnMode is setup like this:



UENUM(BlueprintType)
namespace ESpawnTypeRestriction
{
	enum ESTR_Restriction
	{
		ESTR_AnyType UMETA(DisplayName = "Any Type"),
		ESTR_Inside UMETA(DisplayName = "Only Entites That Are Able to Spawn Inside"),
		ESTR_Outside UMETA(DisplayName = "Only Entites That Are Able to Spawn Outside"),
	};
}

/**
 * 
 */
UCLASS(Blueprintable, Abstract, NotPlaceable, BlueprintType)
class ABRUPT_API AABSpawnMode : public AInfo
{
	GENERATED_UCLASS_BODY()

	public:
		#pragma region Blueprint Implementable Events

		/* How does this mode calculate spawn transforms? */
		UFUNCTION(BlueprintCallable, BlueprintImplementableEvent, Category = "Spawn Mode")
		virtual FTransform CalculateSpawnTransform();

		#pragma endregion

		#pragma region Methods

		/* Spawn a class. */
		UFUNCTION(BlueprintCallable, Category = "Spawn Mode")
		AActor* Spawn(FABEntityInformation entityInformation);

		/* Is the entity compatible with this mode? */
		UFUNCTION(BlueprintCallable, Category = "Spawn Mode")
		bool CheckForCompatibility(FABEntityInformation entityInformation);

		/* Get the closest target point with the specified tag. */
		UFUNCTION(BlueprintCallable, Category = "Spawn Mode")
		ATargetPoint* GetNearestTargetPoint(FVector to, FName tag);

		/* Get the furthest target point with the specified tag. */
		UFUNCTION(BlueprintCallable, Category = "Spawn Mode")
		ATargetPoint* GetFurthestTargetPoint(FVector to, FName tag);

		#pragma endregion

		#pragma region Properties

		/* What types of entities can this mode spawn? */
		UPROPERTY(EditAnywhere, Category = "Spawn Mode")
		TEnumAsByte<ESpawnTypeRestriction::ESTR_Restriction> AcceptedType;

		/* Does this spawn mode require the player to be enclosed? */
		UPROPERTY(EditAnywhere, Category = "Spawn Mode")
		bool bRequiresPlayerToBeEnclosed;

		#pragma endregion
};


This allows me to calculate a transform for a character to spawn at differently. Anyways, all of this leads into the CheckForCompatibility function. This function is called to decide whether or not an enemy can be spawned. ESpawnTypeRestriction lets me choose which type of enemies with certain restrictions are allowed. So for example, if AcceptedType is set to ESTR_Anywhere then enemies with their SpawnRestriction set to ESMR_Anywhere, ESMR_InsideOnly, or ESMR_OutsideOnly can be spawned. Another is if AcceptedType is set to ESTR_Inside then enemies with their SpawnRestriction set to ESMR_InsideOnly can be spawned while the other types can’t. This is where I’m confused though. I’m a little short on sleep and I don’t think I am thinking this through well enough. So here’s what I’m exactly trying to do. What I am trying to do is be able to create different spawn modes and have the game spawn the appropriate enemies in the appropriate positions when the player is in different areas. So the compatibility check is there to see if it should spawn the enemy. If a spawn mode’s accepted type is not compatible with an enemy’s spawn restriction, then that enemy won’t be spawned. I already have the spawning of enemies working and a check in place to see if the player is inside a structure, but I need to get the compatibility check working so it will spawn the correct type of enemies for that specific area. I wouldn’t want to have a huge group of NPCs spawn in a circle inside a building. Another thing is, that I want to have certain enemies be able to spawn both inside and outside. That should only be done outside. I originally tried doing this with booleans instead of enums but I couldn’t get it working. Hope I’m clear enough, lol. It’s a little confusing to me right now. Any help? Thanks! :slight_smile: