Download

Reload of a class that spawns decals results in accumulating decals

I have a class that derives from AActor which spawns a number of decals that are visible in the editor. (I override OnConstruction and call UGameplayStatics::SpawnDecalAtLocation a number of times). Any time I reload my code, I get a new copy of all the decals, but the old ones stay in the scene. I’ve tried overriding RerunConstructionScripts and BeginDestroy and calling DestroyComponent on the decals, but I’m still getting duplicates. How do I properly detect a hot reload and clean up my stuff?

Yo whatup, Inconceivable. Nice name btw, I’m surprised that was available, given that it can be a synonym for “unreal” in the right context. Nice.

Anyway, say you have a TArray of some stuff. Like this:

	TArray<Stuff> things;

to save it as an asset in a package, I think you do this:

	FString packageName = TEXT("/Game/DecalSet/KavalierClay");
	UPackage* package = CreatePackage(*packageName);
	FString packageFileName = FPackageName::LongPackageNameToFilename(packageName, FPackageName::GetAssetPackageExtension());
	UPackage::SavePackage(package, things, EObjectFlags::RF_Public | EObjectFlags::RF_Standalone, *packageFileName, GError, nullptr, true, true, SAVE_NoError);

And then to load it, in BeginPlay or wherever, you do this:

	FString packageName = TEXT("/Game/DecalSet/KavalierClay");
	UPackage* package = CreatePackage(*packageName);
	FString packageFileName = FPackageName::LongPackageNameToFilename(*packageName, FPackageName::GetAssetPackageExtension());
	FString assetName = "HiphopOpotamusMyLyricsAreBottomless";
	things = LoadObject<TArray<Stuff>>(package, *assetName, *packageFileName, EObjectFlags::RF_Public, nullptr);