Positioning question

So i place a Point(small sphere) on an object surface. In another part of my app i need to respawn that Point on the exact same spot on the surface of the object. The catch is that the object is now rotated scaled or translated. How can i find the transform of new point with this info basically: initial object transform, old point relative coordinates and current object transform?

are you working in C++ or blueprints?
are you spawning from an object reference set in your spawners class/blueprint, or the instance? are you spawning the thing by a “soft class reference”

typically when you call SpawnActor in either C++ or Blueprints it will attempt to use the default Transform from its constructor/Construction Script or the Blueprint defaults (at least for scale), and then override the transform based on the transform provided as the input argument. on the next frame you will gain access to modify the Spawned actor.

how exactly are you spawning the actor in question?
are you sure you “MUST” respawn it (create a brand new one)?

  • you can instead of destroying the previous one set it pack to the location and act like it is a brand new one (this might require writing some kind of Reset() with some kind of stored default values for the Object to reset too. you can look up “object pooling” (the most common application is projectiles)
  • this is mostly applicable if you shall only have a known number of entities of the given thing.

I think i did not make myself clear enough so I will reformulate it.

I am trying to recalculate a world-space point based on:

The old object transform (OldTransform)

A point in local space relative to OldTransform (LocalPoint)

A new object transform (NewTransform)

Explanation:
I saved a point on the surface of an object using the object’s transform at that time. Now the object has been moved, rotated, or scaled. I want to place the point back on the same relative spot on the object, but using the object’s new transform. I have:

The original transform of the object

The local position of the point relative to that original transform

The current transform of the object

How do I calculate the correct world position for the point now, so it stays in the same place on the object’s surface, despite the object being transformed?

This is question is not related to actor lifetime, spawn mechanics or object pooling.

I am using C++ and i think i should use the transform methods InverseTransformPosition and TransformPosition. However this gives me wrong results cuz the object spawns someplace else.

I guess I expected “place” instead of “spawn”

to apply a Transform onto another Transform is common enough that FTransform::operator*(FTransform LHS, FTransform RHS) has been overriden to do just that.
NOTE: this function is highly input order dependent so it can and will give very different results depending on order.

given ActorA and ActorB where ActorA has a Relative TransformC
then to place ActorB at the Relative TransformC such that any Transform changes that happened to A will be applied in world space: (this best applications of this presume a default scale of (1.0, 1.0, 1.0) for both Transforms)

// this is TransformC projected into world space relative to ActorA.Transform.
FTransform newWorldTarget = TransformC * ActorA->GetActorTransform();

if this was used to directly Set ActorB.Transform it would remove all modifications made to it.

if you then wanted to preserve modifications made to ActorB.Transform like scaling or rotation then you would need to probably project the newWorldTarget onto ActorB.Transform.

if you wanted to at some point take the current ActorB.Transform into Relative Space of ActorA to replace TransformC that would be

TransformC = ActorA->GetTransform().GetRelativeTransform(ActorB->GetTransform());
1 Like