Accessing Array

Hello,
I ran into a little problem while doing my university project. I created the array of "ABall"s spawned in the level. Problem is that I don’t know how to access it and I cant’ find the answer in the documentation. I Want to access “type” variable and change the “bIsDestroyed”.

Here is my code:
http://pastie.org/10788896

Thanks in advance.

Hi,

You are spawning your actors in your game mode (I guess you have set this GameModeto be the mode used in your level). To access your game mode you have to do something like:

ABallCrusherGameMode* GameMode = Cast<ABallCrusherGameMode>(GetWorld()->GetAuthGameMode());

Remember to check that GetWorld() is not null to avoid crashes. Another thing you have to take into account is that the GameMode is only available on the host instance, so in a server/client scenario clients won’t have an instance of it. If you are creating a network game you have to track your actors in something that you have in both sides like the AGameState which is replicated.

Hope I could help you out.

Well, i think you missunderstood my question. Everything up till this point works just fine. I just dont konow how to access alements in the array I created. For example I want to check the value of the “type” variable of a given ball spawned in the level.

I tried something like this: PlayingFiled[0].type

but it returned errors saying that PlayingFiled[0] has to be a class.

Your array elements are pointers so instead of uaing . you have to use -> to access its members:

PlayingFiled[0]->type

You should also ensure that the index is valid and that the element is not nullptr.

Thank you for your help