Selecting blueprint actor as a character's member variable

I think I see the issue, you are refencing the Skeletal Mesh in your attach to component, not the skeletal Mesh Component, try something like this:

Weapon->AttachToComponent(<EnemySkeletalMeshComponent>, FAttachmentTransformRules::SnapToTargetIncludingScale, "WeaponSocket");

Or depending on your hierarchy, you may want to opt for an “Attach to Actor” instead.

I have buncha blueprint weapons derived from C++ base class and am trying to equip my enemy character with a weapon.

in header:

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Guns, meta=(AllowPrivateAccess = "true"))
	class AMyWeaponBase* EnemyWeapon;

in constructor:

// Equip Weapon
	const USkeletalMeshSocket* WeaponSocket = GetMesh()->GetSocketByName("WeaponSocket");
    if (WeaponSocket && EnemyWeapon)
    {
    	EnemyWeapon->AttachToComponent(GetMesh(), FAttachmentTransformRules::SnapToTargetIncludingScale, "WeaponSocket");
    }

When I try to set a weapon in my enemy character BP, my weapon blueprints doesn’t show up in dropdown, they only show up if I drag them into the level but even then selecting them doesn’t work/do anything. What am I doing wrong?

Kehel18 has the right idea. Alternatively if your weapons are derived from the Actor class you can replace “class AMyWeaponBase* EnemyWeapon;” with AActor* EnemyWeaponActor; and cast it to AMyWeaponBase. You can do this being that all of your classes are derived from AActor.

Hello! The form that you are using allows only Actor to choose, so you can set to this property only Actors of class AMyWeaponBase from some Level. Maybe it will be useful for you to use

TSubclassOf<AMyWeaponBase>

instead.

Thanks, that worked for selection but attachment part didn’t work but that’s a different issue.

// Equip Weapon
	const USkeletalMeshSocket* WeaponSocket = GetMesh()->GetSocketByName("WeaponSocket");
    if (WeaponSocket && EnemyWeapon)
    {
    	AMyWeaponBase* Weapon = Cast<AMyWeaponBase>(EnemyWeapon);
    	Weapon->AttachToComponent(GetMesh(), FAttachmentTransformRules::SnapToTargetIncludingScale, "WeaponSocket");
    }

I couldn’t figure out how to use “EnemySkeletalMeshComponent” in my code.

I’m using the same AttachToComponent() line with GetMesh() in my player character class, it works just fine. There I’m equipping overlapped weapons and switching between weapons all with AttachToComponent(). Here I’m trying to assign/equip with only one specific weapon to the my enemy character.

I moved the code from constructor to BeginPlay() for now cos sometimes things doesn’t work in constructor. If I use anything other than TSubclassOF, weapon blueprints doesn’t show up on my enemy character in dropdown. After fixing editor’s crashing with checking if Weapon is valid after Casting, I think casting doesn’t work somehow.

Also AttachToActor() didn’t make a difference.

Are Skeletons are the same? Sockets are stored in Skeleton asset, so if enemy has another skeleton, socket should be created in it either. Also check Mobility for Weapon actor and take a look at Unreal logs, perhaps they help to find the problem…

Different Skeletons. I created a new slot with the same name in the enemy characters’s skeleton. You reminded me to add ignore collision and stop rotating lines after equipping but adding them didn’t help either.

Only things skeleton related I could see in the logs were some warnings for SocketNames on my player character, nothing for the enemy.

Tried debugging the Cast line, it says: “error = parent failed to evaluate: variable not available”
: