Download

Array of instances and default values

For a game, I wrote a class that defines a “Faction” Data Asset. Within this asset, I define things like the friendly name and materials used for flags and map icons. I also want to define the vehicles and character models used by that faction, so I don’t have to hard code the factions in a level. I define “Environment Types” using a simple UObject. An Environment Type is something like Forest, Desert, Snow, etc. Each Env Type will contain references to assets that define the vehicles and characters. Each faction asset requires at least one “Default” type to fall back to if the game can’t find an Env Type for a faction.

So far, I have this in the Faction class:



// The default environment type
UPROPERTY(EditDefaultsOnly, Instanced, BlueprintReadOnly, Category = EnvironmentSettings)
class UEnvironmentType* DefaultEnvironmentType;

// List of custom environment types
UPROPERTY(EditDefaultsOnly, Instanced, BlueprintReadOnly, Category = EnvironmentSettings)
TArray<class UEnvironmentType*> EnvironmentTypes;


This is the class for Environment Type:



UCLASS(EditInlineNew)
class UEnvironmentType : public UObject
{
	GENERATED_BODY()

	UEnvironmentType(const class FObjectInitializer& ObjectInitializer);

	UPROPERTY(EditDefaultsOnly, Category = "Type Settings")
	FName TypeName;

	UPROPERTY(EditDefaultsOnly, Category = "Vehicles")
	FName UnarmedVehicles[EVehicleSpawn::MAX];

	UPROPERTY(EditDefaultsOnly, Category = "Vehicles")
	FName LightMilitaryVehicles[EVehicleSpawn::MAX];

	UPROPERTY(EditDefaultsOnly, Category = "Vehicles")
	FName HeavyMilitaryVehicles[EVehicleSpawn::MAX];
};


When I create an asset based on this class, both variables will show up as dropdown boxes where I have to select the EnvironmentType class. Is it possible to remove this and immediately instance the class? The array is intended to only contain an instance of that specific class.

Also, I don’t want to hard code a list of possible Environment Types (e.g. as enum), so I intend to use FName to write the Type name, then use that name to search for it in other actors (is there an alternative to assemble a list of all types found for the faction assigned to ). If it can’t find it (either because of a typo or the type does not exist for that faction), it should fall back to the “Default” type. Since the Default type needs to have a fixed name, I want that instance to have a read only name. What comes to mind is to create a copy of the EnvironmentType class and change the UPROPERTY of “TypeName” to VisibleAnywhere with a value of “Default”, but this seems counterproductive.

PS: I am a beginner C++ programmer. Just wanted to say that. If anyone needs more information, please say so.