Jump to content

GetWorldTransform Crashing - Any workaround?

Recommended Posts


I wanted to have a custom action to my own prefab so that it will spawn a vehicle to a location. I created a paratemeter like below:

ref PointInfo spawnPoint;


This is very nice because It would give me referential location for the spawn point. 

Then I have the following code to get the spawn location.

private vector GetSpawnLocation()
  vector position;
  return position;

The crash occurs when I try to GetWorldTransform. It throws a memory access violation and crash the whole Workbench.


I can always use another object as a reference, for example:

IEntity entity = GetGame().GetWorld().FindEntityByName(spawnTarget);
return entity.GetOrigin();

But the problem is that this require me to know the name of the target object to copy the origin. Because I want to configure this on a prefab so that I can reuse the prefab everywhere I cannot rely on component name.


Any other workaround that I could use? Any thoughts?


Thank you!


Share this post

Link to post
Share on other sites

Hi, I needed similar functionality recently and indeed PointInfo crashes for me as well.

Looking at the scripts, PointInfo as attribute is never used in script, but only as attribute in C++ - defined components. I assume that such usage of it is not supported.

So here is my workaround. Not perfect but at least something with visualization. It renders a helper shape while in workbench at the position of that vector offset.

	// This all is in a component class.
	//But for entity class it is also possible to use same approach.
	protected vector m_vDeployablePosition;

	override void _WB_AfterWorldUpdate(IEntity owner, float timeSlice)
		// Visualize the deployable position
		vector deployablePosWorld = GetOwner().CoordToParent(m_vDeployablePosition);
		Shape.CreateSphere(Color.RED, ShapeFlags.ONCE, deployablePosWorld, 0.05);


Share this post

Link to post
Share on other sites

After some time messing around I find a quite easy workaround.

Option 1 is to use a reference object for the Transform which is an array with 4 positions, each one is a vector. 

ref EntitySpawnParams params = new EntitySpawnParams();

Second alternative is as follow

EntitySpawnParams params = EntitySpawnParams();
params.TransformMode = ETransformMode.WORLD;
params.Transform[0] = referenceObject.GetWorldTransformAxis(0);
params.Transform[1] = referenceObject.GetWorldTransformAxis(1);
params.Transform[2] = referenceObject.GetWorldTransformAxis(2);	
params.Transform[3] = referenceObject.GetOrigin();

Pretty clean...


Hope this helps someone else 😀

Share this post

Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in

Sign In Now