Component have zero world location in inherited Blueprint

Component implemented:

UPROPERTY(EditAnywhere, BlueprintReadWrite)
	USceneComponent* Spawner;
Spawner = CreateDefaultSubobject<USceneComponent>(TEXT("Spawner"));
	Spawner->SetRelativeLocationAndRotation(FVector::Zero(),FRotator::ZeroRotator,false,nullptr,ETeleportType::None);
	Spawner->Mobility = EComponentMobility::Movable;
	Spawner->bEditableWhenInherited = true;
	Spawner->SetupAttachment(Model);
	Spawner->RegisterComponent();

But when I get Spawner Coordinates with c++ from Actor where I implements it, Spwner Coordinates are 0,0,0 in world space, but rotaion works fine.

Idea: I want to make a gun c++ class (RangedWeaponActor), where Spawner is Scene Component. I inherit BP Pistol, Rifle from Gun class and I want to move spawner in local space for each weapon. Then in game spawn projectiles in spawner location and rotation. But location is world zero((((((

I have done the same as you: I have a scene component for a weapon which I can adjust visually in blueprint in order to put it near the tip of weapon.

One idea:
In my case, I record the adjusted values that are visible in BP, then write them manually in C++, for example:

FireOrigin->AddLocalOffset(FVector{78, 0, 0}); // {78,0,0} was acquired in BP

Another Idea:
Change the method with which you get the coordinates.
There is GetRelativeLocation() and GetComponentLocation() methods. Maybe you can compare their return values.

Hi there @MasterOfDreams,

Hope you’re well and having a great week so far!

This topic has been moved from International to Programming & Scripting: C++.

When posting, please review the categories to ensure your topic is posted in the most relevant space.

Thanks and happy developing! :slight_smile: