Possible to spawn/use InstancedStaticMesh via Unrealscript?

I’d like to switch out distant clusters of speedtrees with an InstancedStaticMesh (that will set the speedtrees to hidden and show billboards). Thus cutting down draw calls for all the speed trees within a cluster to single call.

I can’t see any way of populating the PerInstanceSMData array in InstancedStaticMesh.uc with data of where I want the trees to display. Does anyone know how to do this?

line 1270 in object file in core folder you have this

native static final function vector TransformVector(Matrix TM, vector A);

it can be used like this to get the placement of your old tree, then I think u can set the new to its location.

local vector V;

V = TransformVector(YourMatrix, YourOldModels.Location);

YourNewModels.Location.X = V.X;
YourNewModels.Location.Y = V.Y;
YourNewModels.Location.Z = V.Z;

Once you scan your old trees then put them into the above function it will spit out that vector. Then you can grab its x, y, z and put that to your new tree. It’s not finished code but that should possibly get you started. Just add in the stuff I didn’t. Like Scanning the old models to get them. Then scan new ones to put it into. Then you should get it working.

Thanks for the response, but it’s how to use an InstancedStaticMeshComponent (via Unrealscript) that I’m trying to figure out. I see no methods in the class to populate the mesh instances. I also don’t see any examples of it being used in Unrealscript code other than the InstancedFoliageActor (where it is all hidden in native code).

try this, you will probably have to edit it a bit.

var class <StaticMeshActor> YourNewType;    
function testtrees()
 local InstancedFoliageActor FoliageActors;  
 local vector YourLocation;  
 local StaticMeshActor YourNewModel;  
 local int j;      

 foreach AllActors(Class'InstancedFoliageActor', FoliageActors)    
   for (j = 0; j < FoliageActors.InstancedStaticMeshComponents.length; j++)        
      YourLocation = FoliageActors.InstancedStaticMeshComponents[j].GetPosition();

      YourNewModel = spawn(YourNewType, , ,YourLocation);          
      FoliageActors.InstancedStaticMeshComponents[j].SetStaticMesh(YourNewModel.StaticMeshComponent.StaticMesh, TRUE );

Thanks for the input, but I’m not quite sure what you’re trying to do here. This would replace all my foliage meshes (of which i have over 1 million on my map) with another mesh. While also spawning a static mesh at the location of each foliage cluster.

Maybe I’m not understanding your strategy with this.

pretty sure adding instanced meshes via unrealscript is not exposed

the closest thing I’ve seen suggested is to have a pool of instancedstaticmeshes already pre-placed in the editor (via foliage paint) and then move them around via code similar to the way gamepainters suggests in his first reply.
it’s cumbersome and limiting, very far from a proper solution - but it might be enough in some cases (i.e. a tree that is used all around the map)

In the second post you would need to add in like a if statement checking a bool. like example if(FoliageActors.InstancedStaticMeshComponents[j].StaticMeshComponent.bIsASpeedTree)

then change it. Add in a new bool. var() bool bIsASpeedTree; to the file StaticMeshComponent. then on your trees in the map check that box on that tree then only that tree will get changed.

Also the YourNewModel maybe extend the file StaticMeshActor to ColdsStaticMeshActor then use that in place of StaticMeshActor from above. then in your new file add in default properties add the tree that will be in ColdsStaticMeshActor.StaticMeshComponent.StaticMesh.

After thinking about all this. It might not work for the fact to get rid of a (static model) tree NODELETE must be false so you can delete it. which would mean you must delete the 1st tree before you set second one or hide it. Until this would be tested not sure if it will work as you are wanting. I have not tried this code(untested) just a thought that came to me.

@Chosker I’m not sure there is a way to move instances via unrealscript, there are few to no methods exposed in the InstancedStaticMeshComponent class.