Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Lets say you have public fixed int pointx[300]; How do you pass it via function?

Discussion in 'Entity Component System' started by goodnewsjimdotcom, May 28, 2021.

  1. goodnewsjimdotcom

    goodnewsjimdotcom

    Joined:
    May 24, 2017
    Posts:
    342
    One more small question before I come back later. Lets say you have public fixed int pointx[300]; //in your IComponentData and you wanted to pass pointX[300] through a function/method. I can't find the exact syntax. Any help?
     
  2. WAYNGames

    WAYNGames

    Joined:
    Mar 16, 2019
    Posts:
    939
    Pass the ICommontentData.
     
  3. goodnewsjimdotcom

    goodnewsjimdotcom

    Joined:
    May 24, 2017
    Posts:
    342
    I want to pass to IComponentData not from.

    Or generally to use in C#.

    Do I pass by a * or something?
     
  4. goodnewsjimdotcom

    goodnewsjimdotcom

    Joined:
    May 24, 2017
    Posts:
    342
    You know, now that I think of it, I don't; have to pass an array. I can just call a function 300 times passing an integer one at a time and reconstruct the array.

    I just thought there was an easy way to pass an array. I guess not.
     
  5. WAYNGames

    WAYNGames

    Joined:
    Mar 16, 2019
    Posts:
    939
    I don't get it.

    If you have an IComponentData that encapsulate the fixed array, just create the IComponentData, assign the fixed array and then pass the IComponentData.

    Calling 300 time a service an reconstructing the array after that seem like a terrible idea.
     
  6. Nyanpas

    Nyanpas

    Joined:
    Dec 29, 2016
    Posts:
    406
    You mean by "ref" in this case?
     
    bb8_1 likes this.
  7. goodnewsjimdotcom

    goodnewsjimdotcom

    Joined:
    May 24, 2017
    Posts:
    342
    You guys seem very very confused, and maybe it is my bad communication.

    Ignore IComponentData, forget DOTS even existed, and we're just C#.

    Lets say I had a class that had an array.

    public fixed int pointx[300];


    and this class had a method:

    public void assign PointXValue( ????? )
    {

    }

    What would the ???? be to accept passing an identical 'public fixed int pointx[300]' from elsewhere?
     
  8. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,626
    You pass it by pointer

    Code (CSharp):
    1. public unsafe struct TestStruct
    2. {
    3.     public fixed int point[300];
    4.  
    5.     public void Pass()
    6.     {
    7.         fixed (int* p = point)
    8.         {
    9.             Method(p);
    10.         }
    11.     }
    12.  
    13.     public static void Method(int* b)
    14.     {
    15.  
    16.     }
    17. }
     
    MNNoxMortem likes this.
  9. goodnewsjimdotcom

    goodnewsjimdotcom

    Joined:
    May 24, 2017
    Posts:
    342
    Tanks super bro terle dude. Party on Garth.
     
  10. goodnewsjimdotcom

    goodnewsjimdotcom

    Joined:
    May 24, 2017
    Posts:
    342
    Wow, I feel doubly blessed! I actually forgot this, then found my own post in the search! I also surprised myself with a joke not knowing it was me. I was like,"Who is this awesome dude with Wayne's World References." Wait, the turtle dude was a guy who helped me before. Wow the awesome guy I didn't know is me! But Tertle is way more awesomer!
     
    OUTTAHERE and apkdev like this.
  11. runner78

    runner78

    Joined:
    Mar 14, 2015
    Posts:
    760
    In the future (>=2021.2) you can also use Span<T> Then you don't have to mess with pointers and can also be used outside of unsafe context.