0

I am using Minions Art grass system, I want to be able to call and regenerate the current mesh on line 301 from another script, I cant find a way to interact with anyhting on this script from another one, so when I generate my mesh, it generates the grass

https://www.patreon.com/posts/grass-system-urp-83683483

Im also using sebastian lagues procedural generation tutorial, using the falloff map

https://www.youtube.com/watch?v=wbpMiKiSKm8&list=PLFt_AvWsXl0eBW2EiBtl_sxmDtSgZBxB3

Im adding a pastebin link so you all can see the code:

[https://pastebin.com/rqcTdUyQ][1]
3
  • 3
    Where is line 301? Most of the code you pasted here is not important at all, just blurring the image, also I'm not sure the tags you added are correct. Could you please shrink the amount of unnecessary code you upload and focus on the code that is causing problems? Commented Jan 24, 2024 at 8:26
  • I updated the question with a pastebin link, thanks for reading Commented Jan 24, 2024 at 15:44
  • @HUGODANIELVALLADOLIDDAUMAS pastebin is offline currently ... a good example why including relevant code here in your question is requested ;) Please refer to minimal reproducible example Commented Jan 31, 2024 at 8:11

1 Answer 1

0

A bit hard to tell from your question and a huge code snippet.

In general: By making the method public static so it can be called from anywhere (assuming the wrapping type is visible of course) ... might need to refactor a bit to not rely on any instance fields but rather take parameters (using ref/out where required)

I didn't count the lines but I will just assume you are referring to CreateNewGrassObject (it's the only non-drawer related thing you included in your question)

So I would convert this to

public static GrassComputeScript CreateNewGrassObject()
{
    var grassObject = new GameObject();
    grassObject.name = "Grass System - Holder";
    var grassCompute = grassObject.AddComponent<GrassComputeScript>();

    // Why is this not simply done in the GrassComputeScript by default on field declaration?
    grassCompute.SetGrassPaintedDataList = new List<GrassData>();

    return grassCompute;
}

all other local values are available then as well anyway via e.g.

var newGrass = GrassPainterWindow.CreateNewGrassObject();
var gameObject = newGrass.gameObject;
var grassData = newGrass.SetGrassPaintedDataList;

Since it contains no editor specific code, you might even consider to move this out into a helper class like

public static class GrassTools
{
    public static GrassComputeScript CreateNewGrassObject()
    {
        ...
    }
}

so it could be available even in a build.

Sign up to request clarification or add additional context in comments.

1 Comment

I cant seem to make this work, I updated my question with a pastelink, is there any chance you could help?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.