Change the pivot of an actor and make it custom size programmatically

Hi!

I’m using Unreal 5.2.1 and I’m trying to draw a line between two actors. I’m not using DrawDebugLine. Instead, first I created a Niaga System Effect but it looks ugly:

So, I decided to do it using a Procedural Mesh. I get the idea from this post 3D Lined Polygon using Procedural Mesh in Unreal Engine with C++ – 3D Developers' Survival Kits.

I have created an Actor component for the procedural mesh, and an actor with this component:

UCLASS()
class MYPROJECT_API APStickActor : public AActor
{
GENERATED_BODY()

public:
// Sets default values for this actor’s properties
APStickActor();

protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;

public:
// Called every frame
virtual void Tick(float DeltaTime) override;

UPROPERTY(EditAnywhere)
class UPStickProceduralMeshComponent* LineComponent{ nullptr };

};

The Procedural component is just a 2D polygon representing a line:

I’m not sure, but I think the component doesn’t start drawing at (0, 0, 0) inside the actor. Instead, the middle point of the component is (0, 0, 0). In other words, if I place this actor in a level at (0, 0, 0), I will have the half side of the line before (0, 0, 0) and the other half side after (0, 0, 0).

How can I make that component start drawing at (0, 0, 0)?

Thanks!

you can acttually place your poly at the midpoint of the desired targets, then orient the poly with lookAt (from point a to B) and finally scale its X using distance from A to B.

midpoint = (pos1 + pos2)/2
distance = vector lenght of pos1-pos2

@eldany.uy Thank you for your answer.

I’ve tried it, but the procedural mesh is on Y axis and I don’t know why.

Is there a way to create the mesh on X axis or rotate the component inside the actor to X axis?

Thanks.

and you can’t scale Y instead?

also…why you want to use a procedural mesh for drawing a line? why not just use a standard static mesh for that?

1 Like

Because I’m a newbie and I’m guessing what to use.

1 Like

Well no so newbie as you using C++ :slight_smile:

Let me try to make a prototype of that with BP and share with you with some video.
If I have time I can move to C++ too.

1 Like

if you hold the mouse button in the YT video you can actually wath it x2 speed :slight_smile:

1 Like

Don’t worry. The problem is that I searched about how to draw a line and someone said that we can’t do that in Unreal, only debug lines. As I have no idea, I didn’t think in other possibilities.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.