Posts: 6
Threads: 2
Joined: Apr 2023
Hi is it possible to animate the UV Offset for the X or Y property. I have tried to do this by clicking on the record button in Unity's Animation Window, but it doesn't seem to pick it up as a property that can be changed over time.
Posts: 2,110
Threads: 92
Joined: Jun 2017
Hi
All the material parameters are internally stored in an array. It seems that the animator does not show members of type Array.
The solution would be then to create a script that will act as a middle man between the animation and the module:
The script will for example have a float V offset value, editable by an animation. The script will every frame apply that value to yourModule.MaterialSettings[yourMaterialIndex].UVOffset.y
Did this help?
Please consider leaving a
review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Posts: 6
Threads: 2
Joined: Apr 2023
(05-25-2023, 09:45 AM)_Aka_ Wrote: Hi
All the material parameters are internally stored in an array. It seems that the animator does not show members of type Array.
The solution would be then to create a script that will act as a middle man between the animation and the module:
The script will for example have a float V offset value, editable by an animation. The script will every frame apply that value to yourModule.MaterialSettings[yourMaterialIndex].UVOffset.y
Did this help?
I wrote the following script to try to control the value, but I seem to be getting an error saying that MissingComponentException, there is no Meshrender attached to the Game Object.
Code:
using UnityEngine;
public class MaterialOffsetController : MonoBehaviour
{
public float vOffset;
public GameObject river;
public int materialIndex;
private MeshRenderer meshRenderer;
private void Start()
{
// Get the MeshRenderer component from the specified GameObject
meshRenderer = river.GetComponent<MeshRenderer>();
}
private void Update()
{
// Update the material's UVOffset.y value based on the vOffset value
Material[] materials = meshRenderer.materials;
if (materialIndex >= 0 && materialIndex < materials.Length)
{
Material material = materials[materialIndex];
Vector2 offset = material.GetTextureOffset("_MainTex");
offset.y = vOffset;
material.SetTextureOffset("_MainTex", offset);
}
}
}
I am setting the script on a empty parent game object and selecting the Curvy Spline Generator as the GameObject. I am pretty sure I am not access the property value correctly.
Posts: 6
Threads: 2
Joined: Apr 2023
Not sure why some of the generators are creating references to the materials that I need to control the vOffset.
And other Generators will only create these Material references in Game Play mode, so I can't control the vOffset.
Posts: 2,110
Threads: 92
Joined: Jun 2017
05-26-2023, 09:50 AM
(This post was last modified: 05-26-2023, 10:02 AM by _Aka_.)
(05-25-2023, 10:05 PM)sam_bond Wrote: I wrote the following script to try to control the value, but I seem to be getting an error saying that MissingComponentException, there is no Meshrender attached to the Game Object.
Code:
using UnityEngine;
public class MaterialOffsetController : MonoBehaviour
{
public float vOffset;
public GameObject river;
public int materialIndex;
private MeshRenderer meshRenderer;
private void Start()
{
// Get the MeshRenderer component from the specified GameObject
meshRenderer = river.GetComponent<MeshRenderer>();
}
private void Update()
{
// Update the material's UVOffset.y value based on the vOffset value
Material[] materials = meshRenderer.materials;
if (materialIndex >= 0 && materialIndex < materials.Length)
{
Material material = materials[materialIndex];
Vector2 offset = material.GetTextureOffset("_MainTex");
offset.y = vOffset;
material.SetTextureOffset("_MainTex", offset);
}
}
}
I am setting the script on a empty parent game object and selecting the Curvy Spline Generator as the GameObject. I am pretty sure I am not access the property value correctly.
You are accessing the wrong things. The script needs to modify the module, which will then be used to generate the objects. Your script tries to modify the generated objects. Here is an example of such script
Code:
using FluffyUnderware.Curvy.Generator;
using FluffyUnderware.Curvy.Generator.Modules;
using UnityEngine;
[ExecuteAlways]
public class ApplyUVOffset : MonoBehaviour
{
public BuildVolumeMesh VolumeMesh;
public int MaterialIndex;
public float UvOffsetY;
private void Update()
{
if (VolumeMesh != null && VolumeMesh.MaterialSettings.Count > MaterialIndex)
{
CGMaterialSettingsEx materialSettings = VolumeMesh.MaterialSettings[MaterialIndex];
materialSettings.UVOffset = new Vector2(
materialSettings.UVOffset.x,
UvOffsetY
);
}
}
}
This script should be attached to a game object in your Unity scene. You'll need to set the VolumeMesh (your module), MaterialIndex (0 for the default material), and UvOffsetY properties in the Inspector. The script will then adjust the UV offset of the specified material every frame.
Did this help?
Please consider leaving a
review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Posts: 6
Threads: 2
Joined: Apr 2023
(05-26-2023, 09:50 AM)_Aka_ Wrote: (05-25-2023, 10:05 PM)sam_bond Wrote: I wrote the following script to try to control the value, but I seem to be getting an error saying that MissingComponentException, there is no Meshrender attached to the Game Object.
Code:
using UnityEngine;
public class MaterialOffsetController : MonoBehaviour
{
public float vOffset;
public GameObject river;
public int materialIndex;
private MeshRenderer meshRenderer;
private void Start()
{
// Get the MeshRenderer component from the specified GameObject
meshRenderer = river.GetComponent<MeshRenderer>();
}
private void Update()
{
// Update the material's UVOffset.y value based on the vOffset value
Material[] materials = meshRenderer.materials;
if (materialIndex >= 0 && materialIndex < materials.Length)
{
Material material = materials[materialIndex];
Vector2 offset = material.GetTextureOffset("_MainTex");
offset.y = vOffset;
material.SetTextureOffset("_MainTex", offset);
}
}
}
I am setting the script on a empty parent game object and selecting the Curvy Spline Generator as the GameObject. I am pretty sure I am not access the property value correctly.
You are accessing the wrong things. The script needs to modify the module, which will then be used to generate the objects. Your script tries to modify the generated objects. Here is an example of such script
Code:
using FluffyUnderware.Curvy.Generator;
using FluffyUnderware.Curvy.Generator.Modules;
using UnityEngine;
[ExecuteAlways]
public class ApplyUVOffset : MonoBehaviour
{
public BuildVolumeMesh VolumeMesh;
public int MaterialIndex;
public float UvOffsetY;
private void Update()
{
if (VolumeMesh != null && VolumeMesh.MaterialSettings.Count > MaterialIndex)
{
CGMaterialSettingsEx materialSettings = VolumeMesh.MaterialSettings[MaterialIndex];
materialSettings.UVOffset = new Vector2(
materialSettings.UVOffset.x,
UvOffsetY
);
}
}
}
This script should be attached to a game object in your Unity scene. You'll need to set the VolumeMesh (your module), MaterialIndex (0 for the default material), and UvOffsetY properties in the Inspector. The script will then adjust the UV offset of the specified material every frame.
Did this help?
This worked perfectly, thank you so much for pointing me in the right direction.
Posts: 2,110
Threads: 92
Joined: Jun 2017
You are welcome.
If and when you feel like it, please leave a review for the asset, that helps a lot.
Have a nice day
Please consider leaving a
review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.