Root Sphere component = none?

    // H
UPROPERTY(BlueprintReadWrite, VisibleAnywhere, Category = "BaseProjectileComponents")
USphereComponent* CollisionComp;

// CPP
CollisionComp = CreateDefaultSubobject<USphereComponent>(TEXT("CollisionComponent"));
RootComponent = CollisionComp;
CollisionComp->SetCollisionProfileName("Projectile");

What did I forget?

How would I specify what kind of CollisionComponent to use in c++? Also when stepping it in VS I find that the CollisionComponent does have a valid UShape and UComponent. Everything seems to be working find except for the details-window.

Using the variable CollisionComp inside blueprints shows “None” as the value… But stepping it in VS shows me a valid object… I’m so confused…

Note that opening the blueprint editor does show me a sphere and it also works ingame. It’s just that the details-window is weird like that showing “None” and the blueprints also showing “None”. But the c++ code is working… How can they even be different.

You did not specify what kind of CollisionComponent you want to use.

Sphere , Capsule, Cube ?

Did you try something like “UBoxComponent”?

Yes I tried those as well but those give me the same problem.

I’m not entirely sure if this will solve your problem, as I only suggest it because it’s the convention I’m familiar with in my experience (so maybe somebody else can elaborate on more of the “why”), but I believe in your .cpp, in your constructor, you forgot to add your ObjectInitializer and a “this” parameter. At least in my knowledge, I’ve always seen the component initialized as such, so maybe that’ll fix your issue:

// CPP
CollisionComp = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(this, TEXT("CollisionComponent"));
RootComponent = CollisionComp;
CollisionComp->SetCollisionProfileName("Projectile");

And then to use the object initializer you need to make sure the constructor looks something like:

AClassName::AClassName(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)

Hopefully this solves your problem

ABaseProjectile::ABaseProjectile(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)

error C2511: ‘ABaseProjectile::ABaseProjectile(const FObjectInitializer &)’: overloaded member function not found in ‘ABaseProjectile’

It’s parentclass is AActor. So I checked the AACtor definition:

	/**
	 * Default constructor for AActor
	 */
	AActor();

	/**
	 * Constructor for AActor that takes an ObjectInitializer
	 */
	AActor(const FObjectInitializer& ObjectInitializer);

That’s weird… That should work. I bet I’m overlooking something very simple again.

I believe that issue is with the header file. I forgot to mention that by putting the object initializer in your constructor, you also need to do so in your header. In your header, replace your old constructor declaration with:

	ABaseProjectile(const FObjectInitializer& ObjectInitializer);

Ah of course. I added it and now it compiles. But sadly the same result:

Have you tested it just to see if it collides at all by spawning an instance of it into your world, changing the Collision Profile to “BlockAll,” and dropping a kinematic box on it or something? That might glean some more information, because if it does collide properly in that case there’s the possibility that it’s a quirk of unreal. But I can’t find issue with the code at all, so it’s something else at play. Is the image of a blueprint class that is derived from the base c++ class you included above? Sometimes the mixing of the two can create some unexpected results.

Yes that projectile is directly derived from BaseProjectile. As you can see it has a collisionbox (yes that box actually works when playtesting). The projectile also moves so that means that the ProjectileMovementComponent must have recognized the CollisionComponent as something valid I guess.

But in the blueprint code it says (=error) that the CollisionComponent is “None” whenever I use it and the details panel as you can see also displays this weird thing. But as long as I don’t use the details panel and don’t use it in blueprints this code oddly enough works perfectly.

But I kinda want it to work in blueprints + I kinda want to be able to modify the box in child-blueprints so I can make it fit the projectile mesh.

And yes it slowly starts looking like an UE4 bug but I’m not sure yet. I might have some macro or something else setup incorrectly. I just have no idea what it could be.

I also tried the code below, but same result:

UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "BaseProjectile|Components")

So it was an Unreal bug. ALL of the child-blueprints deriving from BaseProjectile are corrupted… Recreating them fixes the problem entirely. Luckily I was about to convert those to C++ anyway. Blueprints are just so unstable even though their stability has been significantly improved over the last year.

We noticed the corruption because the blueprints were acting really strange and some of the variable values started displaying impossible values.