How can I resolve the error "Unrecognized type 'TSubobjectPtr'" while generating code?

I’m experiencing an error during the code generation phase of building my project. I added an actor via the UE4.1 C++ wizard, named AProjectileBasicExplosion. Following the first person template for Projectile.h, I created the following header file:

#pragma once

#include "GameFramework/Actor.h"
#include "ProjectileBasicExplosion.generated.h"

/**
 * Explosion actor
 */
UCLASS(config=Game)
class AProjectileBasicExplosion : public AActor
{
	GENERATED_UCLASS_BODY()

	/** Explosion Particle Component */
	UPROPERTY(VisibleAnywhere, Category=Particle)
	TSubobjectPtr<ParticleSystemComponent> ExplosionParticles;
	 
	/** Force Component */
	UPROPERTY(VisibleAnywhere, Category=Force)
	TSubobjectPtr<RadialForceComponent> ExplosionForce;

	UFUNCTION()
	void Explode();
};

Upon compiling, I receive the following failure:

1>------ Rebuild All started: Project: FugitiveRush, Configuration: Development_Editor x64 ------
1>  Cleaning FugitiveRushEditor Binaries...
1>  Parsing headers for FugitiveRushEditor
1>C:/Users/Axel/Documents/Unreal Projects/FugitiveRush/Source/FugitiveRush/ProjectileBasicExplosion.h(18): error : In ProjectileBasicExplosion: Unrecognized type 'TSubobjectPtr'
1>Error : Failed to generate code for FugitiveRushEditor - error code: 4
1>EXEC : error : UnrealHeaderTool failed for target 'FugitiveRushEditor' (platform: Win64, module info: C:\Users\Axel\Documents\Unreal Projects\FugitiveRush\Intermediate\Build\Win64\FugitiveRushEditor\Development\UnrealHeaderTool.manifest).
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.MakeFile.Targets(43,5): error MSB3073: The command ""C:\Program Files\Unreal Engine\4.1\Engine\Build\BatchFiles\Rebuild.bat" FugitiveRushEditor Win64 Development "C:\Users\Axel\Documents\Unreal Projects\FugitiveRush\FugitiveRush.uproject" -rocket" exited with code 1.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

It seems that TSubobjectPtr is defined in Runtime/CoreUObject/Public/UObject/UObjectGlobals.h, however since it is not included in the Projectile.h template, I assume that this header file is included in either the .generated.h file or more likely the Actor.h file. I’ve read the manual, but it hasn’t cleared up my issue. So I guess my question is twofold:

  1. How can I fix this error message, and what am I doing wrong?
  2. Are there implicit dependencies within the first person template project files? Why does the generated file for ProjectileBasicExplosion.h need to include Actor.h while the template file Projectile.h not? If so, what are they and where are they configured?

Thanks for the help.

Why VisibleAnywhere? Component will be always visible in component editor regardless what specifier you gonna use.

I didn’t realize that. I saw it in the other template and it seemed like a straightforward way to make it configurable in the editor. Do you think it is related to the issue?

Try changing your TSubobjectPtr< ParticleSystemComponent > to TSubobjectPtr< UParticleSystemComponent > and same thing with the RadialForceComponent (Don’t forget the U)

And if that still doesn’t work, then change it to TSubobjectPtr< class UParticleSystemComponent > and same with RadialForceComponent. One of those should work.

Thanks! That did the trick.

Also I feed silly now.

No worries, no need to feel silly. We are all learning here, I can say that I have made the same mistake numerous times now and probably even sillier mistakes :stuck_out_tongue: