How To Pass An Array Into An Array

Hi there,
Is there a way to pass one array into another? Meaning, I have an array, it has about a hundred members. I just created a new array, with identical members, just a different class. In code, can I swap the already set array members of class Script, to new array class Transform?

Use an object array for example.

But remember that classes in C# are reference types, that might cause you some problems later :wink: Just a hint

However the best solution is often to re-think your design :wink:

Anything that inherits from MonoBehaviour can access the transform it’s attached to anyway…

Indeed :wink:

You’re talking about members… do you mean elements or is it not really an array but actually a class with 100 members? I wonder if something like AutoMapper would work in Unity. AutoMapper is a tool I use frequently in my day job translating between data and domain models… if your properties are identical (or close) it will automatically translate them, but you can define your mappings and even translate between different properties. It’s available as a NuGet package or here:

http://automapper.codeplex.com/

Wanted to add that once your mapping is setup it’s as easy as calling:

Mapper.Map(srcObject, destObject);