• Advertisement
  • Popular Tags

  • Popular Now

  • Advertisement
  • Similar Content

    • By Alexia
      Hi all,
      A small team are currently undertaking a fairly large game project involving multi-playing, taming and other complex game mechanisms.
      We are looking for someone who is experienced in programming a wide range of mechanisms, more information is on our discord server. It is also a learning experience and we wouldn't expect you to know how to do everything we wanted, but just ask that you would be willing to learn how to.
      If you are interested in joining the (rather long term project) just message me and i'll add you on discord.
      Thanks for your time,
      Alexia 
    • By davemacdo
      I'm a formally trained composer (doctorate from Michigan State) who writes what most people would call avant-garde concert music. I love weird abstract projects, and I would like to work with somebody making a weird, abstract, artsy game. 
      You can find more about me and my music on my site. I have worked with acoustic and electronic sounds, including some procedurally generated and interactive computer music. 
      In particular, I would like to work on a project that lets me use Fmod to prepare an adaptive score for a game built on Unity or Unreal. I've been a music professor and would like to get experience working in this medium so that I can be a better mentor for my students. Send me a DM or email <davidjohnmacdonald@gmail.com> if you would like to discuss working on a project together. 
    • By Tuner_z

      Name: One Level: Stickman Jailbreak
      Price: Free
      Developer: RTU Studio
      Platform: Android
      Language: C# (Unity3D)
      Google Play: https://play.google.com/store/apps/details?id=com.RTU.OneLevel
       
      Hello!
      I want to show you my game! "One level: Stickman Jailbreak" is a puzzle game with unusual gameplay where you must help the character to escape from prison. You just need to take the key and get out alive. The game has only one level, and there are many ways to complete it. Not everything is as simple as it might seem at first glance, so there are clues in the game.
       
      Short description:
      Nobody escapes from here!
       
      Description:
      Tommy got into trouble again! Our hero is behind bars. But he's not going to stay in jail for a long time and he decides to escape. Tommy steals a key and gets out of the jail cell. But our friend doesn't go free: Tommy suddenly finds himself in the same room from which he just escaped! The conditions for escaping change every time. In order to go free Tommy will have to solve logical puzzles and you can help him in this!
      At first it will be easy, but the tension will increase, and the tasks will become more complicated with each level. You should use your brain for all 100%, but if your skill is not enough, you can use a hint or ask for help from friends!
      You can solve the puzzles alone or with your friends and spend time well!
       
      Features: 
      Features:
      - 48 unique levels;
      - the game is translated into 10 languages: English, French, German, Spanish, Italian, Portuguese, Russian, Japanese, Chinese, Korean;
      - the function of "help from friend";
      - hints;
      - instructions.
       
      Trailer:
       
      Screenshots:





       
    • By Brandon Marx
      Hello forum,
      I have some decent amount of experience in Unity making games for Software Engineering projects in college, these were very specific projects however and I still am fairly new to building games. I wanted to make a game that uses the shadows of objects for collision detecting (i.e. shooting a gun at a characters shadow causes that character damage. What is the best engine to do this in (game will be 3D), and does anyone have any advice on how to approach this concept? I consider myself fairly experienced in programming, but game dev is just an entirely different beast.
    • By juicyz
      Hey all,
      I've been slowly working on my game called AotW for a while now.  I have come to the conclusions that it would be nice to cooperate with 1 or 2 others to help finish it.  Ive been trying to keep my GDD up to date with my ideas and development so that would give a better overview of the game when the time comes.  Currently I have a basic skeleton of the RPG elements needed but everything can still be discussed and talked about and we can transform my idea to something the group likes.
      The premise of the game is a Diablo-like procedurally generated map with RPG elements that include sockets, inventory, classes, abilities, crafting, loot, items, sockets, and enchanting.  This will be done in a 2D iso view as I can't do 3D art and I enjoy 2D games a lot.
       
      I don't plan on releasing this as this is more of a hobby project for me and I have a full-time job.  Though I'd like to start putting more hours into development and having others definitely will be motivation.  I also want to be able to say I have finally "finished" a game idea to some degree.  If the time comes and we want to release it, then we can go ahead and do so but that's not my purpose or plan. 
       
      Discord:
      Juicyz#3683
       
       
      Thanks,
      Juicyz
  • Advertisement
  • Advertisement
Sign in to follow this  

Unity Declaration of structures

This topic is 740 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How can one declare a structure (more specifically an array of structures) inside another structure in C#? Tried something I found on the Microsoft website and it doesn't appear to work for Unity. If anyone could provide me an example or point me in the right direction, that would be extremely helpful ...

Thanks.

Share this post


Link to post
Share on other sites
Advertisement

Because C# structs are value types, rather than reference types, fixed arrays like that are not permitted.

 

You can create a struct member that is a reference, such as:  public MyOtherStruct[] name;  You'll then need to allocate the array and manipulate it on your own.

 

You cannot create a fixed array except for primitive types, such as: public fixed int items[256];  However, that use is not recommended for several reasons. Value types should be kept small if possible.

Share this post


Link to post
Share on other sites
public struct SimpleStruct
{
    public int Foo;
    public int Bar;
}

public struct StructOfArrayOfStructs
{
    public SimpleStruct[] Elements;
}
When you say "Doesn't appear to work for Unity", EXACTLY what do you mean? Edited by Nypyren

Share this post


Link to post
Share on other sites
When you say "Doesn't appear to work for Unity", EXACTLY what do you mean?

 

No, I meant that for structures inside other structures, not for vectors of structures. I can't seem to be able to instantiate the variables. I'm not even sure if it's possible right now.

Share this post


Link to post
Share on other sites

I'm going to take a wild guess that you're trying to use an array of structs as a member of a MonoBehaviour or ScriptableObject.

If that's the case, you need to put the 'Serializable' attribute on your structs for them to appear in Unity's inspector and get serialized to asset files:
 

[Serializable] // using System;
public struct SimpleStruct
{
    public int Foo;
    public int Bar;
}

[Serializable]
public struct StructOfArrayOfStructs
{
    public SimpleStruct[] Elements;
}

Share this post


Link to post
Share on other sites

When you say "Doesn't appear to work for Unity", EXACTLY what do you mean?

 
No, I meant that for structures inside other structures, not for vectors of structures. I can't seem to be able to instantiate the variables. I'm not even sure if it's possible right now.


Ok, I posted my second message before I read this.

Structs have slightly different construction rules than classes. What are you trying? Can you show some code?

Share this post


Link to post
Share on other sites


when you post questions like this without providing the exact and complete error messages.

(Bold fix)

 

I would also add that you (4detc) should also include the actual code which produces those error messages.

Share this post


Link to post
Share on other sites

 

When you say "Doesn't appear to work for Unity", EXACTLY what do you mean?

 

No, I meant that for structures inside other structures, not for vectors of structures. I can't seem to be able to instantiate the variables. I'm not even sure if it's possible right now.

 

For reasons that only god knows, Unity uses a terribly outdated version of mono. Possibily for stability and support reasons. Though that won't make much sense give that prior to the upgrade to Unity 5, they upgraded to a SLIGHTLY newer version of mono. Which is really just maybe a slight step up the revision.

 

Now... are you talking about defining a structure inside a structure? If so I wasn't even aware that was a legal action.

Share this post


Link to post
Share on other sites

Now... are you talking about defining a structure inside a structure? If so I wasn't even aware that was a legal action.


It's allowed. I haven't seen it in real code yet, though...

I don't know of anything Mono or Unity specific regarding structs that differs from the usual .Net, either (besides internal implementation details, of course). Edited by Nypyren

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement