methusalah / SplineMesh

A Unity plugin to create curved content in real-time with bézier curves
https://twitter.com/dumas181
MIT License
1.05k stars 104 forks source link

Spline mesh not scriptable? #25

Closed edisyo closed 5 years ago

edisyo commented 5 years ago

Hey,

first of all thanks for the asset. Bu my problem is, that im trying to change scale X of spline mesh tiling via script. Its changing in console, but I can't see the changes in play mode.

Is there something im doing wrong? Help will be much appreciated :)

splineMesh.scale.x += splineMesh.scale.x * Time.deltaTime; splineMeshProblem

Here you can see, that the scale of x variable has been changed to 2 (was 0.1). But no changes in editor or play mode :/ When X is 2, the spline should have "grown", where number 2 is in picture, but it has stayed in place.

EDIT: Also when I animate variable X, the value changes in animation, but the spline isn't updating.

methusalah commented 5 years ago

Optimisations in SplineMesh allows to bend an object very fast, but the object needs initial preparation. This is why SplineMeshTiling don't listen to object changes during play time.

What you want to do is change the object at each frame, which may be time consumming, depending on what you are trying to do.

You can achieve it easily by setting SplineMeshTiling.toUpdate to public and set it to true each time you change the scale. This way the whole bent mesh will be re-created each time.

edisyo commented 5 years ago

thanks for the fast reply, will try that when i can.

EDIT: It works really good now, thanks. Except, when I am changing scale via script, device starts to be laggy. Could there be a way to reduce the lag?

programming2012 commented 3 years ago

Optimisations in SplineMesh allows to bend an object very fast, but the object needs initial preparation. This is why SplineMeshTiling don't listen to object changes during play time.

What you want to do is change the object at each frame, which may be time consumming, depending on what you are trying to do.

You can achieve it easily by setting SplineMeshTiling.toUpdate to public and set it to true each time you change the scale. This way the whole bent mesh will be re-created each time.

Hi I set SplineMeshTiling.toUpdate to public, and after change the scale i set it to true. Some time it is re-created, and some time i reopen the Unity editor, it no effect I had to add these code to the FindOrCreate Method of SplineMeshTilling. private GameObject FindOrCreate(string name) { var childTransform = generated.transform.Find(name);

        Destroy(childTransform.gameObject);
        childTransform = null;

        GameObject res;

And then i click the Play button of Unity. Run once, And delete the above scripts. The run after of this All is OK. I do not why. If you know the problem, maybe you can help me. Thanks.

programming2012 commented 3 years ago

I add these code to OnEnable Method. Like below. May be it can use.

    private void OnEnable()
    {
        // tip : if you name all generated content in the same way, you can easily find all of it
        // at once in the scene view, with a single search.
        string generatedName = "generated by " + GetType().Name;
        var generatedTranform = transform.Find(generatedName);
        if (Application.isPlaying)
        {
            if (generatedTranform != null)
            {
                Destroy(generatedTranform.gameObject);
                generatedTranform = null;
            }
        }

    generated = generatedTranform != null ? generatedTranform.gameObject : UOUtility.Create(generatedName, gameObject);