Possible to change foliage mesh during gameplay?

I’d like to update things like the material (and potentially the mesh itself) of instanced foliage meshes on my map.

I can update the scale, and set them to hidden, but not change the mesh.

Does anyone know how this could be done?

I don’t know of any way to change the mesh during gameplay. I don’t suppose it would be enough to use two masked material instances and use a parameter hooked up to the opacity masks to turn one kind of foliage on and the other off?

Edit: Nevermind. You can already set them to hidden, which I guess means you can unhide them. So you can already show/hide the meshes, and my suggestion doesn’t get you any further. (Unless you wanted to do a fancy dissolve between the meshes?)

Thanks for the response. Yes i think i’ll have to use material parameters to adjust the visual look. Another way (although a bit hacky) is to store another mesh in the final LOD and adjust the LodDistanceRatio to hide it from showing, then tweak it to use only the last LOD.

You can scan them like this. We added parameters to the materials instances to change to what we wanted.

to get the ground landscape textures.


  
   foreach AllActors(Class'Landscape', AllMapMats)
      {                  
        for (j = 0; j < AllMapMats.LandscapeComponents.length; j++)        
        {            
          if (WeatherSetting == 3)
            AllMapMats.LandscapeComponents[j].MaterialInstance.SetScalarParameterValue('Rain', 1);            
          else if (WeatherSetting == 4)             {              
            AllMapMats.LandscapeComponents[j].MaterialInstance.SetScalarParameterValue('Snow', 1);            
         }        
        }  

get the textures on foliage.



 foreach AllActors(Class'InstancedFoliageActor', FoliageActors)    
   {        
       for (j = 0; j < FoliageActors.InstancedStaticMeshComponents.length; j++)        
       {          
          CurMat = MaterialInstanceConstant(FoliageActors.InstancedStaticMeshComponents[j].GetMaterial(0));                                 CurMat2 = MaterialInstanceConstant(FoliageActors.InstancedStaticMeshComponents[j].GetMaterial(1));          
          CurMat3 = MaterialInstanceConstant(FoliageActors.InstancedStaticMeshComponents[j].GetMaterial(2));    
           if (WeatherSetting == 3)            
             {                
                if(CurMat != none)                
                {                  
                  CurMat.GetScalarParameterValue('Rain',GetFloat);

                  if(GetFloat != 1)                    
                   CurMat.SetScalarParameterValue('Rain', 1);                
                }                

                if(CurMat2 != none)                
                {                  
                   CurMat2.GetScalarParameterValue('Rain',GetFloat);                    
                   if(GetFloat != 1)                    
                     CurMat2.SetScalarParameterValue('Rain', 1);                
                }    

                if(CurMat3 != none)                
                {                  
                  CurMat3.GetScalarParameterValue('Rain',GetFloat);
                  if(GetFloat != 1)                    
                   CurMat3.SetScalarParameterValue('Rain', 1);                
                }            
              }            
              else if (WeatherSetting == 4)            
              {                
                if(CurMat != none)                
                {                  
                  CurMat.GetScalarParameterValue('Snow',GetFloat);                  
                  if(GetFloat != 2)                    
                   CurMat.SetScalarParameterValue('Snow', 2);                
                }  

                if(CurMat2 != none)                
                {                  
                   CurMat2.GetScalarParameterValue('Snow',GetFloat);
                   if(GetFloat != 2)                    
                     CurMat2.SetScalarParameterValue('Snow', 2);
                }

                if(CurMat3 != none)                
                {                    
                  CurMat3.GetScalarParameterValue('Snow',GetFloat);
                  if(GetFloat != 2)                    
                    CurMat3.SetScalarParameterValue('Snow', 2);                
                }              
           }  
     }
    }

Thanks for the response. Yes i’m doing something very similar. Btw you can update the landscape material by just accessing the LandscapeMaterial property in Lanscape (rather than iterating over each component).

I do wish there was a way to switch the foliage mesh though. I can hack around using material parameters, but I don’t see why this limitation is in place, when i can update the scale, material, etc of the foliage meshes.

I do not think you can change the mesh, as those are static models that are put into the foliage editor. I have been able to change the meshes on skeletal meshs during play, but not static models.

OK, here’s a crazy idea: Using Blender or the 3D editor of your choice, combine both meshes into the same fbx file. Make a texture atlas so that the two different meshes use the same material. Then create a masked material that has a parameter to change which side of the material is masked. Then during gameplay, change that parameter and you can change which mesh shows up in that location.

That’s an interesting idea. When I get some time. I will try that and see what results I get.

We added code to hide models (static and skeletal) when the maps loads. Once loaded static meshs could not be hidden. I tried hiding a scoreboard and it would not hide unless it was skeletal. From my experience, All I could get to change was the materials instances parameters we put into the material.