playMaker

Author Topic: Array List Get not working  (Read 1137 times)

curb47

  • Sr. Member
  • ****
  • Posts: 256
Array List Get not working
« on: March 04, 2021, 02:49:42 AM »
Hiya,

I've got a problem with Array List Get.

I have my master control object (COMETS) which manages the spawning/waves of sentient beings.



Some objects (SpaceTargets) are put into an Array. These objects are just Empty Game Objects that the Sentients fly towards.



When the Sentients are spawned (pooled/spawned prefabs), the COMETS object is set on each one as a Game Object variable. All good so far.





Okay, now the fail...

When the Event is triggered to send the sentients whizz towards the SpaceTargets, the Array List Get is not working. I've double checked all my variables, and logic, and I can't see any reason why this is happening. I must be overlooking something but I can't figure out what it is.





Any help is greatly appreciated.

Many thanks,

J.
« Last Edit: March 04, 2021, 04:58:09 AM by curb47 »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Array List Get not working
« Reply #1 on: March 04, 2021, 06:54:06 AM »
Hi.
You should set a failure event,
Do you have any warnings in the console?

Are the comets added to the array in the same frame?
if so try to add a next frame after the comets added to the list, before getting them.

curb47

  • Sr. Member
  • ****
  • Posts: 256
Re: Array List Get not working
« Reply #2 on: March 04, 2021, 08:12:28 AM »
Hello.

Can I set a failure event just to loop around back into the same state, so it tries again to grab the item from the Array list?

I have no warnings in the consol.

The comets (now called sentients) are added to an array, but only to receive a Send Event by Name to Array List.

My naming convention is a bit confusing, because COMETS refers to the manager that deals with all the spawning of the sentients. The actual prefabs of the comets, I'm now calling sentients.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Array List Get not working
« Reply #3 on: March 04, 2021, 12:41:15 PM »
Hi.
in most cases you should set this event to a state with a breakpoint or a debug error so you know it has issues.

double check the reference also, it happend to me already that it had a space in it and then it does not find also a Enter can cause this issue and you cant really see it in the text line.

Also try using breakpoints when its getting from the array to see step by step.


curb47

  • Sr. Member
  • ****
  • Posts: 256
Re: Array List Get not working
« Reply #4 on: March 04, 2021, 01:05:02 PM »
Hiya,

Okay, thanks. Umm... what's a 'breakpoint' ?

J.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Array List Get not working
« Reply #5 on: March 04, 2021, 05:52:03 PM »
Hi.
Have a look to this video :)


curb47

  • Sr. Member
  • ****
  • Posts: 256
Re: Array List Get not working
« Reply #6 on: March 05, 2021, 02:02:14 AM »
Thank you, I'll check that out.

I did a little test and set up another simple FSM which tries to access an array on the same COMETS object, and I'm having the same problem. It's weird.



The logic should work, right?

curb47

  • Sr. Member
  • ****
  • Posts: 256
Re: Array List Get not working
« Reply #7 on: March 05, 2021, 02:14:49 AM »
I tried adding a Failure Event, which just goes to another State which also tries to access the same array list. This one also has a Failure Event which goes back to the first State, so a continuous loop if they both fail.

I was expecting to see this continuous loop happening, but it didn't, the flow went through to the next set of states. So, the Array List Get is not registering the fail? Or maybe the Array list isn't populated at the moment the action looks at it?

Maybe I need to add a Wait 0.5 somewhere in the mix?

« Last Edit: March 05, 2021, 04:33:53 AM by curb47 »

curb47

  • Sr. Member
  • ****
  • Posts: 256
Re: Array List Get not working
« Reply #8 on: March 05, 2021, 02:47:56 AM »
Just to clarify, the Sentients are pooled/spawned prefabs.

These prefabs are having the COMETS object set on them immediately after spawn, by using Set FSM Game Object (which you taught me, many many months ago!):



Just to avoid any confusion, you can see the 'Prefab To Spawn' is 'New RedComet'. This is just the name of the prefab, but I'm calling them 'sentient' as the Spawned Game Object.

The spawned Sentient prefab can 'see' the COMETS game object, which has the array lists on it, so am I right in thinking that as long as the connection has been made, the Sentient should be able to access the array lists on the COMETS object?

You can see on this screen grab above, the spawned sentients are added to their own array list on the COMETS object. When you start shooting one of the sentients, as its health drops it sends an event to all sentients on the array list:



This action works just fine, so the connection is there.
« Last Edit: March 05, 2021, 04:34:19 AM by curb47 »

curb47

  • Sr. Member
  • ****
  • Posts: 256
Re: Array List Get not working
« Reply #9 on: March 05, 2021, 12:04:19 PM »
I tried setting the array up on the spawned sentient, but still encountering problems. Although this time I'm getting errors in the consol which is a good thing, because at least it gives a clue on how to fix it.

Problem is, I have no idea what it says...



Any idea on how to interpret this?

Thank you.

J.

RobotGoggles

  • Playmaker Newbie
  • *
  • Posts: 35
Re: Array List Get not working
« Reply #10 on: March 07, 2021, 11:56:05 PM »
NullReferenceException means a GameObject is being accessed, but hasn't been defined. It's either actions you're trying perform on the GameObject you're not getting or some other GameObject that's null in your FSMs.
When life hands you insomnia, make video games.