raycasting – Can I cache and edit Unity RaycastCommands?

I’m simulating a LiDAR and am working to optimize the code. In following along with the RaycastCommand documentation, I have the core functionality working and I’m trying to optimize it.

I see where the commands and results are being created as NativeArrays with the Temp allocator, so I made them member variables and initialize to the correct size with the Persistent allocator on Start and Dispose them OnApplicationQuit.

However, this still leaves me new-ing thousands and thousands of RaycastCommands every Update. I’d like to initialize the commands once and then just iterate through the NativeArray and change the from and direction properties, which are public according to the documentation, but I’m getting an error that I can’t do that when I try.

I’m trying to move the LiDARs through the scene, so I need the origin (from) and direction to change, but I don’t want to keep calling all those new commands – is there some way to cache and edit the commands that I’m not noticing? I can’t tell why from and direction are public if I’m not allowed to set them.

I’ve done years of Unity development in Windows with Visual Studio and have recently moved to Linux and VS Code and the auto complete is frankly awful by comparison. It’s making it hard for me to look through the autocomplete options for possible alternatives.