Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Create a collider ( SplinePathMeshBuilder)
Hi again Jake,

I'm trying to make a dynamic Mesh Collider for my mesh having the "SplinePathMeshBuilder" script.
Something like :

GetComponent(MeshCollider).sharedMesh = null;
var mesh : Mesh = GetComponent(MeshFilter).mesh;
GetComponent(MeshCollider).sharedMesh = mesh;
And... it works but then I can't Edit the shape anymore with the curvySpline Script.

Is there any build in code in order to do that properly ?
I didn't find anything in the doc.

Thanks a lot !
Did you tried to use the sharedMesh from the MeshFilter? Besides that, what exactly means you can't edit it any more?
Thank you for your quick answer Smile
Yes, I tried to use the sharedMesh from the MeshFilter.

Well, when I "re-build" the collider of my "spline mesh" with the code above, then his script "SplinePathMeshBuilder" stops to work.
That"s to say, if I edit any of its value : Shape Radius, UV mode... or if I change the position of a Control Point it has no effect at all. There is something broken.


I just checked with the MeshBuilder example. I added a MeshCollider to the RoadPath GameObject and additionally this script (MeshColUpdate.cs):

using UnityEngine;
using System.Collections;

public class MeshColUpdate : MonoBehaviour {
    MeshFilter mFilter;
    MeshCollider mCol;

    // Use this for initialization
    void Start () {
        mFilter = GetComponent<MeshFilter> ();
        mCol = GetComponent<MeshCollider> ();
    // Update is called once per frame
    void Update () {
        mCol.sharedMesh = null;
        mCol.sharedMesh = mFilter.mesh;

Of course that's horrible slow, but the Collider updates properly when I change Extrusion parameters or modify the underlying spline. Can you test the above script with the example scene, just to be sure this behaves the same on your side?




Amaziiiiing !!!!! Jake !

Just perfect ! thank you so much for your script, it was exactly what I was looking for Smile


I am trying to use this script as it seems like a solution to my issues as well. However whenever I copy and paste the script in My scene gives me this error:

Assets/TestScript.cs(10,53): error CS1525: Unexpected symbol `)'

I do not code so Im not sure exactly how to fix it, I have tried to delete the symbol it finds unexpected but that just causes other issues.

I am using Playmaker to create my game but I was hoping to find a way of getting this script to create a collider for me.
Any help would be much apreciated.

The wysiwyg editor of the forum scrambled my initial input. I just updated the code, it should work now. It's pretty easy to create a custom action out of it, I'll hopefully get the time to do this tommorow.

Great thanks a bunch for that!

One thing of note is that when you use a mesh collider on the object that is collinding with this roadpath it falls right through still, so you need to use primative colliders to get it to work. But thats not too much of an issue for me.

Cheers Jake.
Just a note that updating any existing mesh collider is now part of v1.61.

Possibly Related Threads...
Thread Author Replies Views Last Post
  Trying to create a moving train that slows and stops at stations Novian 7 1,767 09-13-2018, 08:46 PM
Last Post: ClaudePorter
  Curvy to create splines from 3D models Sergei543071 1 782 08-07-2018, 02:34 PM
Last Post: _Aka_
  Curvy spline to 2D Edge collider _Aka_ 1 1,164 03-09-2018, 07:23 PM
Last Post: _Aka_
  Create an arrow dynamically following the spline yandrako 25 17,680 02-28-2018, 12:21 AM
Last Post: _Aka_

Forum Jump: