playMaker

Author Topic: Copy ArrayList runtime content  (Read 1939 times)

cc099183

  • Playmaker Newbie
  • *
  • Posts: 17
Copy ArrayList runtime content
« on: February 03, 2019, 01:26:45 AM »
I have a problem, I want to copy arraylist content at runtime.
I know arraylist has a "Copy Arraylist Content" command,
but I want to copy hundred even thousand arraylists...
If I copy one by one, it needs a lot of time to do.
Have any way to do this more easier?

Sorry, my English is poor...

cc099183

  • Playmaker Newbie
  • *
  • Posts: 17
Re: Copy ArrayList runtime content
« Reply #1 on: February 03, 2019, 11:49:06 PM »
Hm...I have another question.
How do I use a script to add a sprite into PlayMakerArrayList?
I tried array.add but it doesn't work.
« Last Edit: February 03, 2019, 11:51:38 PM by cc099183 »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Copy ArrayList runtime content
« Reply #2 on: February 04, 2019, 01:25:58 AM »
Hi,

when in doubt, simply open the action that does what you want to do maually, im your case ArrayListAdd.

- get a reference of the PlayMakerArrayListProxy component
- <proxy>.Add(yourValue,yourValueTypeAsString,false)

or more directly

- <proxy>.arrayList.Add(yourValue);

Bye,

 Jean


cc099183

  • Playmaker Newbie
  • *
  • Posts: 17
Re: Copy ArrayList runtime content
« Reply #3 on: February 04, 2019, 02:48:45 AM »
It can run, but the arrayList isn't get the value and show error "NullReferenceException".
This is my code, I want this script run in editor.
I don't know where is wrong...

   
Code: [Select]
public string spriteSheetName;
    public int arrayNumber;
    public SpriteRenderer NowRender;
    public PlayMakerArrayListProxy myArray;
    public Sprite Now_Sprite;

void LoadImage() {
   
        var subSprites = Resources.LoadAll<Sprite>(spriteSheetName);

        if(arrayNumber >= subSprites.Length){


}
 
        else{

NowRender.sprite = (Sprite)subSprites[arrayNumber];
Now_Sprite = (Sprite)subSprites[arrayNumber];
myArray.arrayList.Add(Now_Sprite);


}

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Copy ArrayList runtime content
« Reply #4 on: February 04, 2019, 03:25:51 AM »
Hi,

If this is a spriteSheet, you can't extract sprites like that. It's supposed to work the other way around, spritesheets are internal optimization, you should reference the sprite itself, and under the hood, Unity will pick it up from its spritesheet.

Can you explain your case and what you are trying to achieve?

 Bye.

 Jean

cc099183

  • Playmaker Newbie
  • *
  • Posts: 17
Re: Copy ArrayList runtime content
« Reply #5 on: February 04, 2019, 03:45:40 AM »
I want to put all sprites in arrayList, and I can use it to change my character's color(Image).
It's a hard work to put them into arrayList one by one.
I want to find a way to put all sprites in arrayList easier, so I ask how to copy all arrayList value from runtime, but I think it doesn't.
So I need to find another way.
I want to make a script run in editor to put sprites in arrayList.
But it seems doesn't too?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Copy ArrayList runtime content
« Reply #6 on: February 04, 2019, 03:52:28 AM »
Hi,

 - put your sprites in a Resources folder.
 - you can then load them at runtime using a string reference which is the path within the Resources folder.

you can make an editor script, but again, you can't use spritesheets directly, you need to use sprites assets. you can make a routine that loads all your resources from a given folder and then put them in an array proxy, your first step is to make a simple test to se if you can put one, then you build up from that by loading resources, and iterate through them.

Bye,

 Jean

cc099183

  • Playmaker Newbie
  • *
  • Posts: 17
Re: Copy ArrayList runtime content
« Reply #7 on: February 04, 2019, 04:06:34 AM »
I used this way before.
But it will spend a lot of time in loading sprite.
Hm...It seem doesn't have another way to do this...

And thanks for your help!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Copy ArrayList runtime content
« Reply #8 on: February 04, 2019, 04:11:00 AM »
Hi,

how many sprites to do you have?

 it should not take any time to load if they are referenced in your array in your scene, it's when you load from resources directly that you might have to watch out for spikes, and even so, if the spritesheet is loaded, it will be instant.

Bye,

 Jean

cc099183

  • Playmaker Newbie
  • *
  • Posts: 17
Re: Copy ArrayList runtime content
« Reply #9 on: February 04, 2019, 04:27:14 AM »
I used "Resources.LoadAll<Sprite>(spriteSheetName)" to load and put them into arrayList.
And I have about 15000 sprites.
1 spriteSheet contain many sprites in it.
It needs many time to put all sprite in arrayList.

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Copy ArrayList runtime content
« Reply #10 on: February 04, 2019, 02:13:55 PM »
Hey guys, i've got a similar issue but it has been overlooked, please check it out: https://hutonggames.com/playmakerforum/index.php?topic=19776.msg86501#msg86501
Available for Playmaker work

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Copy ArrayList runtime content
« Reply #11 on: February 05, 2019, 01:51:15 AM »
Hi,

yes, there is currently no simple ways to copy from runtime and paste back during edit time.

about the 15000 sprites and spriteSheet, I think you are misunderstanding ( or maybe I do) how sprites and spritesheets work.

- Who created the spritesheets? you? from an external software or within Unity using its built in packer?

15000 sprites is a lot even for big projects.
- what's your naming convention for these sprites?
- what do you plan to do with them at runtime?
- how many will be used during a typical gameplay?


referencing a sprite that is it self contained in a spritesheet is the way to go. that's it, if you want to extract a sprite from a sprite sheet fully, then it will create more memory consumption, that's not what you want since you made a spritesheet for it, so this goes against the optimisation principle of using spritesheets to want to extract sprites from it. you want to "use" sprites, and for this you simple reference it from the assets folder, Unity deals with packing under the hood.

maybe you could give a concrete example and we have a better base to work out your feature and how best to implement it.

Bye,

Jean

cc099183

  • Playmaker Newbie
  • *
  • Posts: 17
Re: Copy ArrayList runtime content
« Reply #12 on: February 05, 2019, 04:38:27 AM »
Hi,

I send a example to you.
I write some comment in it.
I'm not a programmer and my English is poor, so maybe it's hard to understand.
And thanks for your help!