Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Including scripts on created meshes
#1
Question 
Hi -- big fan of this asset, which powers a lot of the procedural generation in my roguelike/racer. I use Curvy to generate prefab road chunks that I mix and match in my level generator. In Curvy 7, I was able to add scripts to created meshes (generated by the Create Mesh tool) which then were automatically passed on to the generated meshes created at runtime. In the editor, I simply added the scripts to the created mesh (contained within a prefab with a Curvy spline), and the scripts appeared on the created mesh in game accordingly.

Since I updated to Curvy 8, this approach doesn't work anymore. I will add the scripts to the created mesh object contained with in a Curvy spline prefab. But the moment I save the prefab and spawn it in game (or return to the prefab in editor), the Create Mesh tool creates a new mesh that is missing the scripts I added.

There are a number of tiles in my game that require these additional scripts to be added to generated meshes. I suppose I could contain the scripts on another object in these prefabs and reference them to the child of the Create Mesh object, but for simplicity's sake it would be great if I could add these scripts to the created meshes in a consistent way like I could with Curvy 7. 

Any tips here? Thanks!
Reply
#2
Hi

The solution I thought of right away is a variant of your solution: having a game object in the prefab that would do the operation on all the generated meshes. The difference between both our solutions is that mine would reference the Create Mesh module itself, and iterate through all its children, instead of referencing the children one by one.

If you want a behavior close to the old one, here is a solution. But I have to advise you: I do not recommend to rely on that old behavior, because it relies on the fact that edit mode was running before play mode, which will not be the case when you will build your project. There are also other scenarios were the old behaviour you described would not appear, even in Curvy 7. This being said, here is the solution: go to CGMeshResourceLoader.Destroy (in CGResource.cs). There, find this line:
obj.StripComponents(typeof(CGMeshResource), typeof(MeshFilter), typeof(MeshRenderer));
and replace it with
obj.StripComponents(typeof(CGMeshResource), typeof(MeshFilter), typeof(MeshRenderer), typeof(your_script));

I hope this helped
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 will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Photo Can't export custom collision meshes Mike Danielsson 5 7 10-14-2022, 10:36 AM
Last Post: _Aka_
Bug Severe bug with some types of Prefabs/meshes studentloan 17 39 07-23-2022, 11:19 AM
Last Post: _Aka_
Question Add Component to created mesh? HarvesteR 1 16 05-25-2022, 07:21 PM
Last Post: _Aka_
  Can I extract prefabs from Curvy's generated meshes? niuage 7 18 03-15-2022, 11:44 AM
Last Post: _Aka_

Forum Jump: