playMaker

Author Topic: Alternative to Tag system  (Read 1709 times)

misterjuly

  • Sr. Member
  • ****
  • Posts: 334
Alternative to Tag system
« on: September 25, 2021, 05:17:21 PM »
Hello,

I have a bunch of blocks that will be able to be mined. However, I do not want to put a tag on each block so it can register to be destroyed whenever I mine it. I want it to be based on collision without tags. Each block has its own collider on it. How do I make it so I can do this? Thanks!

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Alternative to Tag system
« Reply #1 on: September 26, 2021, 08:41:11 AM »
have a fsm on the objects with a variable.
make sure on all blocks to use the same fsm name, for example 'Data'
call the for example "block Type"

you can use a int or string. and you can get the type when you need it.

misterjuly

  • Sr. Member
  • ****
  • Posts: 334
Re: Alternative to Tag system
« Reply #2 on: September 26, 2021, 09:38:41 AM »
So, if I understand this correctly, I put the same FSM with the same name on all objects that I want to interact with the same way, then I use the same int or string to call the name of the FSM? Which action would I use to call the name of the FSM? Thanks!

John Bassi

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Alternative to Tag system
« Reply #3 on: September 26, 2021, 02:28:56 PM »
Hi.
No, on the fsm add a variable with the same name

on collision store the object, then use Get Fsm Int/String (Fsm Name : Data / Variable Name : Block Type)


wetcircuit

  • Full Member
  • ***
  • Posts: 158
    • wetcircuit.com
Re: Alternative to Tag system
« Reply #4 on: September 26, 2021, 05:35:04 PM »
Said another way..., there is a variable on the block that takes the place of a tagging system. When the collision happens, you could read the variable on the collided object.

The fsm on the blocks can be passive. they don't need events or actions, just the variable. All the action happens through your player controller (whatever that is) that collided with the block.

Groo Gadgets

  • Beta Group
  • Full Member
  • *
  • Posts: 175
Re: Alternative to Tag system
« Reply #5 on: September 27, 2021, 10:45:56 PM »
I would avoid adding an FSM to every block, especially if you intend to have hundreds of blocks in your scene.

An extremely simple solution would be to embed the required variable data into the name of the block object itself. This way you can embed multiple values into the name of the block and simply read the name of the block on collision.

Example: BLOCK_TYPE_HEALTH

BLOCK: this string or int value denotes what kind of object it is
TYPE: this would typically be an int value if you have multiple block types
HEALTH: an int value representing the health of the block

The actual name of the object can look like this: BLOCK_1_80

To process these values you just need one FSM in your scene that handles collisions. On collision you would use the "Get Name" action, then use the "String Split" action and set the separator to an underscore to separate each of the 3 values into an array.

So if want to destroy a block with about 4 hits, you would want to read the health value and subtract the power of each hit from the health. Let's say the power of your hit is 20, then 80 - 20 = 60 and so on until the health value is 0 or less.

Remember each time you execute this function you can easily write the values back to the name of the object.


The great thing about this technique is the status of each of your blocks in the scene is easily readable by simply looking at the names of the blocks in your hierarchy.

I've been using this technique for years and it has served me well, I hope it helps!

Cheers,

Simon

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Alternative to Tag system
« Reply #6 on: September 28, 2021, 12:18:51 PM »
Hi.
I had a 'minecraft' like test build a few years ago which had fsms on the blocks and that worked fine.
not sure why you would want to avoid.

But another way you could detect is by material.

wetcircuit

  • Full Member
  • ***
  • Posts: 158
    • wetcircuit.com
Re: Alternative to Tag system
« Reply #7 on: September 28, 2021, 03:37:31 PM »
I like the idea of storing data as the name of the object… :D

I build procedural models with lots of parameters that are set when the models are stamped… would be an option to store info without adding another script or keeping track of a db.

Groo Gadgets

  • Beta Group
  • Full Member
  • *
  • Posts: 175
Re: Alternative to Tag system
« Reply #8 on: September 28, 2021, 08:49:51 PM »
not sure why you would want to avoid.

This technique is simple and easy to implement with zero overhead on each block. If you have 500,000 blocks in your Minecraft test then you would also have 500,000 FSM's in your scene without this method   8)

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Alternative to Tag system
« Reply #9 on: September 28, 2021, 11:59:41 PM »
hi.
Actually you wont have so may blocks loaded at the same time in minecraft.
at least on our test we did not, as you only need exposed layers :)

Also we needed to store some data on it for how many times it got hit by a pickaxe for example.

it worked fine, but now i would probably use a different approach with grid based arrays.

Groo Gadgets

  • Beta Group
  • Full Member
  • *
  • Posts: 175
Re: Alternative to Tag system
« Reply #10 on: September 29, 2021, 12:17:41 AM »
Actually you wont have so may blocks loaded at the same time in minecraft.
at least on our test we did not, as you only need exposed layers :)

Also we needed to store some data on it for how many times it got hit by a pickaxe for example.

500k is an extreme case but you would have many thousands of blocks visible in even the most basic Minecraft scenes.

The point is you can store a lot of data "for free" if you embed it in the object name, without the need for any attached scripts. The object name can essentially become a basic CSV which is easily processed per interaction.

This is the cheapest solution I've found to deal with data on many instanced objects  ;D

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Alternative to Tag system
« Reply #11 on: September 30, 2021, 08:31:18 AM »
I would avoid adding an FSM to every block, especially if you intend to have hundreds of blocks in your scene.

An extremely simple solution would be to embed the required variable data into the name of the block object itself. This way you can embed multiple values into the name of the block and simply read the name of the block on collision.

Example: BLOCK_TYPE_HEALTH

BLOCK: this string or int value denotes what kind of object it is
TYPE: this would typically be an int value if you have multiple block types
HEALTH: an int value representing the health of the block

The actual name of the object can look like this: BLOCK_1_80

To process these values you just need one FSM in your scene that handles collisions. On collision you would use the "Get Name" action, then use the "String Split" action and set the separator to an underscore to separate each of the 3 values into an array.

So if want to destroy a block with about 4 hits, you would want to read the health value and subtract the power of each hit from the health. Let's say the power of your hit is 20, then 80 - 20 = 60 and so on until the health value is 0 or less.

Remember each time you execute this function you can easily write the values back to the name of the object.


The great thing about this technique is the status of each of your blocks in the scene is easily readable by simply looking at the names of the blocks in your hierarchy.

I've been using this technique for years and it has served me well, I hope it helps!

Cheers,

Simon

Wouldn't that create a lot of garbage since strings are immutable?
« Last Edit: September 30, 2021, 08:40:49 AM by Fat Pug Studio »
Available for Playmaker work

Groo Gadgets

  • Beta Group
  • Full Member
  • *
  • Posts: 175
Re: Alternative to Tag system
« Reply #12 on: September 30, 2021, 09:24:57 PM »
Wouldn't that create a lot of garbage since strings are immutable?
Not sure how reading and writing object names would create garbage?

It's not like i'm reading the name of every object into one big array, I only read and write a single object based on the kind of event (in this case; on collision).

How do you think this technique would create garbage?

wetcircuit

  • Full Member
  • ***
  • Posts: 158
    • wetcircuit.com
Re: Alternative to Tag system
« Reply #13 on: October 01, 2021, 08:32:01 AM »
 ::) The psychological resistance to simple ideas is fascinating…. The human brain will rationalize any excuse to agree with preconceived bias.

I brought up this name-tag idea in my procedural community and they kept insisting it was useless because a gameobject name "can't store a long string with punctuation…"
 ;D hahahaha

Nevermind the models' parameters do not involve strings at all (currently using CSV of ints, bools, and floats). LOL!