Announcement

Collapse
No announcement yet.

Possible to spawn/use InstancedStaticMesh via Unrealscript?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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?

    #2
    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.
    Last edited by gamepainters; 10-31-2019, 11:44 AM.

    Comment


      #3
      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).

      Comment


        #4
        try this, you will probably have to edit it a bit.
        Code:
        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++)        
           { 
                 if(FoliageActors.InstancedStaticMeshComponents[j].StaticMeshComponent.bIsASpeedTree)  
            {    
              YourLocation = FoliageActors.InstancedStaticMeshComponents[j].GetPosition();
        
              YourNewModel = spawn(YourNewType, , ,YourLocation);          
              YourNewModel.StaticMeshComponent.SetHidden(FALSE);          
              FoliageActors.InstancedStaticMeshComponents[j].SetStaticMesh(YourNewModel.StaticMeshComponent.StaticMesh, TRUE );
            }          
           }    
          }  
        }
        Last edited by gamepainters; 10-31-2019, 11:39 AM.

        Comment


          #5
          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.

          Comment


            #6
            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)
            Follow me on Twitter!
            Developer of Elium - Prison Escape
            Local Image-Based Lighting for UE4

            Comment


              #7
              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.

              Comment


                #8
                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.
                Last edited by Coldscooter; 11-05-2019, 07:35 PM.

                Comment

                Working...
                X