ActorComponent None

I didn’t mention it but, my actor component is not a charactermovement component, it inherits directly from UActorComponent. My charactermovement component instantiates just fine. My actor component was introduced on ABeing that inherits from ACharacter

Hey guys! Need some help!

I have a base c++ class for our game characters called Being, and I have a custom actor component that I want to have in it as a DefaultComponent… Everything was fine until I moved from 4.15 to 4.17

Now when I play the game with a character Blueprint-Inherited from this class, I always get a None value… Am I doing something wrong? I followed the creation code of UCharacterMovementComponent in Character.h and Character.cpp to the last word.

Being.h

ABeing(const FObjectInitializer& ObjectInitializer = FObjectInitializer::Get());

//Name of the CounterHolder component
static FName CounterComponentName;

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "General|Being|Public", meta = (AllowPrivateAccess = "true"))
		class UCounterHolder *CounterHolder;

Being.cpp

FName ABeing::CounterComponentName(TEXT("CountHoldComp"));

ABeing::ABeing(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{
	PrimaryActorTick.bCanEverTick = true;
	//Do not use ControllerYaw to rotate character's mesh, use velocity's direction to rotate the mesh instead
	bUseControllerRotationYaw = false;
	if (GetCharacterMovement()) {
		GetCharacterMovement()->bOrientRotationToMovement = true;
	}

	//Create CounterHolder as default component to being, set it to replicate and activate on it's own
	CounterHolder = CreateDefaultSubobject<UCounterHolder>(ABeing::CounterComponentName);
	if (CounterHolder) {
		CounterHolder->SetIsReplicated(true);
		CounterHolder->bAutoActivate = true;
	}
	
}

Thanks for any help you can provide,

Hello, on the constructor on the .cpp you are missing the cmc initialisation:

ASprunchCharacter::ASprunchCharacter(const class FObjectInitializer& ObjectInitializer) 
	: Super(ObjectInitializer.SetDefaultSubobjectClass<USprunchCharacterMovement>(ACharacter::CharacterMovementComponentName))
{
	// Jumping
	JumpMaxHoldTime = 0.3f;

	// Set size for collision capsule
	GetCapsuleComponent()->InitCapsuleSize(42.f, 66.0f);

	// set our turn rates for input
	BaseTurnRate = 45.f;
	BaseLookUpRate = 45.f;

        ...
}

Oh! Sorry, in that case let’s make a bit of failsafing.
Be sure your component has the following metas:

UCLASS(ClassGroup = Weapons, meta = (BlueprintSpawnableComponent), Blueprintable)
    class SHOOTERGAME_API UShooterWeapon_ComponentInstant : public UShooterWeapon_FiringComponent
    {
    	GENERATED_UCLASS_BODY()
    
    ....

then on your .h of your actor you want to attach said component:

private:
	/** Main firing component */
	UPROPERTY(VisibleDefaultsOnly, Category = Weapon)
	class UShooterWeapon_ComponentInstant* InstaHitComponent;

and finally on the cpp of the actor you are attaching this:

AShooterWeapon_Instant::AShooterWeapon_Instant(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
	InstaHitComponent = CreateDefaultSubobject<UShooterWeapon_ComponentInstant>(TEXT("InstaHitComponent"));
}

Yep, all of this was right. The strangest part is that I spawn other Actors from this component, and they really are spawned, so something is wrong here, it exists, but it doesn’t? It show on the list of components in blueprintclass, but when selected never shows on detail panels

Be sure that all your UPROPERTIES in the component are “exposed” to Blueprints

Ok… Discovered that the important part is that a went from 4.15 to 4.17.

Seems like a bug, but I deleted the blueprint class, and recreated it and it solved the problem… The downside is that I needed to re-do all the functionality on the new blueprint class…

Thanks for all the help and attention @vorixo,

I had a similar problem, and did in fact notice it worked if I created a new child blueprint class based on the C++ class. I managed to fix the problem by renaming the component variable.

PlayerEquipment = CreateDefaultSubobject<UEquipmentComponent>(TEXT("PlayerEquipment"));

to

PlayerEquipment2 = CreateDefaultSubobject<UEquipmentComponent>(TEXT("PlayerEquipment2"));

This bug is a pain to deal with; but at least doing it this way you won’t have to recreate the class and its functionality.