How to use GetComponentsBounds in C++?

Hi, I want to do something like this in C++, how to do it…

What I am trying is:

	FVector Origin;
	FVector BoxExtent;
	float SphereRadius{};
	bool EqualEqual{};
	float BreakVector_X{};
	float BreakVector_Y{};
	float BreakVector_Z{};
	FVector MakeVector;
	FHitResult AddActorLocalOffset{};
	if (bSpawnedItem)
		UKismetSystemLibrary::GetComponentBounds(StaticMesh, Origin, BoxExtent, SphereRadius);
		UKismetMathLibrary::BreakVector(BoxExtent, BreakVector_X, BreakVector_Y, BreakVector_Z);
		FVector MakeVector = UKismetMathLibrary::MakeVector(0.000000, 0.000000, BreakVector_Z);
		AActor::AddActorLocalOffset(MakeVector, false, AddActorLocalOffset, false);

I don’t see any mistake in your code but … should be FHitResult* AddActorLocalOffset{};

1 Like

Thank You for Help for solving the compiling issue, but still I don’t want to use KismetLibrary, it seems to me I can’t do it without using KismetLibrary.

you can do it without using kismetlibrary, code your own custom getter function GetComponentsBounds by some basic math calculations and use it instead of using kismetlibrary.

The second thing is according to your bp script the AddActorLocalOffst = K2_AddActorLocalOffset and than you can use local variable FHitResult AddActorLocalOffset{}; instead of global pointer *

hope it helps! cheers

1 Like

like this ?
FHitResult AddActorLocalOffset{};
AActor::K2_AddActorLocalOffset(MakeVector, false, AddActorLocalOffset, false);


1 Like

Thank You very much for solving the Issue, I really appreciate it… at least the code now compiles and get the correct results as expected.
But still looking for the non-kismetlibrary solution :stuck_out_tongue_closed_eyes:

Don’t overcomplicate things.

if (bSpawnedItem)
    AddActorLocalOffset(FVector(0, 0, StaticMesh->Bounds.BoxExtent.Z));

Thank You Sir for the Solution , I really appreciate that You just solved my Issue :slight_smile: