Hey.Sorry for my English )
I am working on a stylized grass / plant setup for a 2D game.
I need plants to have bend / rotate to have rotation animation. Each in its own random phase of rotation.
I also need a plant response to the player.
Plants must be instances and use 1 drow call.
Final setup looks like this, but I have a couple more questions:
At the test level, there are about a hundred blueprints of plants.
I made the rotation through the shader using RotateAboutAxis, Sine function and WorldPositionOffset.
The reaction to the player is implemented in blueprints: when the player overlap the plant, a timeline animation is launched in the plat blueprint.
Everything worked fine, AutoInstancing system converted my static meshes blueprints to instances and i have 1 draw call for all plants.
But all plants rotated in one phase. And this phase need to be randomed. I have to add a random number to the sine function in shader (with which I did the rotation).
https://forums.unrealengine.com/filedata/fetch?filedataid=177219&type=thumb&attachmentnodeid=
I thought we also have a shader node PerInstanceRandom and we have instances created by the engine. They definitely should work together. But unfortunately per instance random does not work with AutoInstancing.
Is this a bug or features of the functions of autoinstance and randomization?
In fact, I suspect that PerInstanceRandom necessarily requires an InstancedStaticMeshComponent in instanced actor blueprint.
Next for randomize the rotation phase I I tried to use the material parameter, which on each plant instance was set randomly through DynamicMaterialInstance in the construction script.
https://forums.unrealengine.com/filedata/fetch?filedataid=177214&type=thumb&attachmentnodeid=
Rotations were randomized, but In this case I had a separate drow call for each palnt. Autoinstance did not work. As I suppose, this was due to the fact that each plant created its own instance of the material with the phase shift parameter. (If I’m wrong, please write).
Having not found a better solution, I returned to the first setup and instead of using PerInstanceRandom I used ObjectPositionWS -sum of x and y positions for sin phase offset.
I do not think that this is the best option for randomizing instances.
Final questions:
Please tell me if there are better solutions in my conditions?
Is it possible to set a random in shader level for AutoInstanced object not through a world position?
Using DynamicMaterialInstance disable AutoInstancing ?
P.S.
I tried to make all the plants in one bluprient using InstancedStaticMesh.
I received 1 draw call, but for the reaction of plants to the character, I need to know the instance index with which the character interacts. I did not find this function in blueprints. Can someone know the solution to such a setup through InstancedStaticMesh?