Import coordinates as CSV

Hi, I don’t really understand why once I read the CSV files and write them into listX, listY and listZresult vectors, as can be seen in the attachment, if I try to take them inside a Vector3 structure Unity tells me that those vectros don’t exist. Can please someone help me? Thanks but I’m new to Unity and I find it quite complex

7407959–905714–Move.cs (2.21 KB)

where is the code where you use Vector3?

here is example of creating new vector3:

1 Like

Sorry I uploaded an old version. Here it is

7408025–905723–Move.cs (2.53 KB)

whats the actual error message in console?

maybe listZresult in the last for loop is smaller array than listX.Count?

1 Like

it says that no listX, Y and Zresult exists. But when I start it outside Unity, as I developed it, with Visual Studio, it works correctly since I added in that case a WriteLine to check the contents of the 3 vectors. Also if I use it outside Unity the 3 vectors have the same length

oh i see, you have your lists inside this scope:
static void Main(string[ ] args)
{

}

and you try to access them here, they are not available.

remove that static void main stuff, and have all that code inside Start()

1 Like

Ok, now that part I think works, but there are other problems. I attach the new script and the image of the errors. Thanks

7408400–905831–coordinates.cs (2.42 KB)

can check with File.Exists() if the path is correct,

usually i put readable data files into Assets/StreamingAssets/
then can access them with path:

(they will be included in the build, as a visible folder, so can replace or edit those data files without rebuilding exe)

1 Like

Ok I placed a debug to check if they exist or not and it seems that they exist. Now the (I hope) last problem is at the end, in fact I saved all the data as double but I think that Vector3 works with float, I tried to apply what I found on the web to convert it but it doesn’t work. Do you have any suggestion?

this doesnt work:

x = float(listX[i]);

can cast into float using (float)

1 Like

Ok, now it works. Now I only have to make it follows the proper trajectory. Thanks

nice.
you could loop the values inside Update() method, increment index once a frame,
or using coroutine (which is kind of like a fake threading, that you can add delay into)

1 Like

Hi, I tried with the Update() but it dowsn’t work. I uploaded the script I used, at first I recalled the variables inside the Start(), then instead, I recalled them inside Update(). With the start nothing happens and I also think that this is not the correct way. With the Update() it doesn’t work. I attached the errors given by Unity


7415084–907007–coordinates.cs (3.25 KB)

its the scope issue again, those variables are declared inside Start() so they are not available outside it.
so move them to class level, outside the Start().

https://tutorialspoint.dev/language/c-sharp/scope-of-variables-in-c-2

1 Like

Hi, here I am again. I don’t really understand how to use the coroutine but before if I’m going to print the actual coordinates once each cycle, they seemes wrong, can you please try to make me understand why? Moreover, my aim is to simulate a 3d printer, do you also know how can I make the plastic filament deposited following the nozzle of the printer? (Until now I applied the script to a cube to understand if it works or not).

Thanks in advance

7421768–908249–coordinates.cs (3.28 KB)

could rename void Update() into

IEnumerator Animate()

then start that coroutine after you have finished loading, end of Start(),

StartCoroutine(Animate());

then inside Animate() method,
loop your data one by one, with 1 frame delay

for(var i=0;i<listX.Count;i++)
{
   // your code to get values for i, then move cube to that position
   yield return 0; // wait 1 frame
}

for simulating 3d printed material generation,
i guess could search for something like: unity marching cubes
(basically its a 3d grid/, and changing cell value above 0 creates (iso)surface on that space…)
not sure if its good enough for 3d printer simulation though… but can try.

also initially you could test by spawning cubes on those positions, to see how it looks,

1 Like

I tried what you said with the coroutine but there was an error (CS1001), so I searched on the web and I tried like I uploaded but now seems the coroutine doesn’t start. Do you know why?

Thanks for your patience but I really don’t understand

7421927–908291–coordinates.cs (4.13 KB)

are you calling Move() somewhere?

No, but if I neglect Move() and use only the StartCoroutine(Animate()); alone, it returns the CS1001 error, while if I add the Move() it doesn’t return errors but the cube doesn’t move

code works for me, can you copy full error message (and which line it happens)?