Return a custom class from function

I have a variable that is of type class. Within that class is a variable of another class type.

I need to change the values of the class within the class, and I thought I could do that by creating a function that can return the type class. But I can’t seem to figure out how.

I know I could do this with a constructor, and pass in the values I need, but it would be so much nicer if you could create a function that returns the class instead.

Can you do this?

Thanks for your help,

sorry, yea reading this back it doesn’t really make a lot of sense.

so I have a couple of classes, with one of them holding the other class as a variable.

public class bezier {
		public Vector3[] controlPoint;
		public float length;
		public boundingbox boundary; 

	public class road {
		public int typeIndex;
		public int[] intersection;
		public bezier[] spline; 

I then declare a new variable of type “road”. I later need to change the information in spline. There’s a lot of information in spline, and I was hoping I could do something like this :

example.spline = SetSplines(some inputs...);

with SetSplines being a function, that returns the data type spline.

Spline SetSplines (parameters){

        ....using the paramaters, add values to the spline class
       return theSplineInfo


I didn’t add what Id like to do in the function, its not really relevant

Now you cant do this, because you cant make the type of the function some custom type. The work around would be to make it a void function, and have it save to some temporary variable of type spline, and then copy the contents of this temporary variable into example.spline . But that’s really messy, and I was hoping there was a workaround. :slight_smile: Thanks


Well, so lets start over. Since your “spline” variable is of type bezier[] your SetSplines method has to return an array of bezier, not a single bezier.

bezier[] SetSplines()
    // create a bezier array which you return at the end

Since you said it doesn’t matter what your method does we’re done here.