#Scripts added twice (Editor bug)

1 messages · Page 1 of 1 (latest)

versed flame
#

There are some steps to clean up any errors in the project

livid cradle
#

D:

versed flame
#

That screenshot

#

Two Components of the same kind on the same object

#

that's a huge error

livid cradle
#

only happens with scripts so far

versed flame
#

oh wait

#

it is possible xD
but for it to happen at the same time, is obviously a bug

livid cradle
#

so it's not a problem with my project?

versed flame
#

Can you safely Save and Exit the project right now?

livid cradle
#

it started to happen randomly

#

yeah

#

I can save and close it just fine

versed flame
#

Alright. Do that.
Then navigate to the project folder, and delete the folder named Library

livid cradle
#

alright

versed flame
#

There is a lot else that can also be deleted, but try it with just that first.

livid cradle
#

35k files lol

#

it's gone

versed flame
#

The Library folder will be regenerated upon project start.

livid cradle
#

give me 10 years till it's done opening

#

it's back up

#

still gets added twice

versed flame
#

Alright. And you don't have a line with AddComponent in your script?

livid cradle
#

in the script I am dragging in?

#

no

versed flame
#

yeah

#

kk

livid cradle
#

happens with every script

versed flame
#

Exit the project again. Delete the Library folder.
Next, make a compressed archive to backup your project, before we proceed.
What type of project is it so far?
Is it a game, or an Editor Script project?

livid cradle
#

it has both

versed flame
#

How many days or weeks work is in this project?

livid cradle
#

like a month or two

versed flame
#

Alright. With a backup, we can safely delete stuff here and there.

livid cradle
#

it would suck to lose the progress :P

versed flame
#

With a backup you are entirely safe. You can even copy the entire project folder to another drive or whatnot.

#

With that much work, you need to be certain.

livid cradle
#

making a zip of the folder rn

versed flame
#

I'll explain some about project composition.

livid cradle
#

it's just a shoddy space invaders clone so nothing valuable but it's my 2nd overall game project

versed flame
#

The factors which make Unity recognize this folder as a Project, is that is contains the folders:
Assets, Packages, and ProjectSettings
And that there is a valid ProjectVersion.txt inside ProjectSettings.
UserSettings is also a keeper, but can technically be discarded, as Unity would generate a default.

#

When you have 2 backups, you can delete the following:

livid cradle
#

2 backups?

versed flame
#

One for each month's work ^^

livid cradle
#

oh

#

hah

#

I only have a backup of the current stuff, no in between ones

#

but it's all on github

versed flame
#

oh yes I forgot to ask if you were using Version Control.
Is your project fully backed up there?

livid cradle
#

I have some changes that aren't committed but otherwise yeah

versed flame
#

Alright.
I would make two backups.

livid cradle
#

of the same files?

versed flame
#

the entire project folder

#

but I'm not sure how many GB you're at

livid cradle
#

1.3

#

nothing wild

versed flame
#

Balanced

livid cradle
#

alright I zipped my project folder twice

versed flame
#

Folders to delete:
Library
Logs
obj
Temp

Files to delete:
All files directly inside project root, except .vsconfig (I really doubt that's the culprit)

#

Though you could

livid cradle
#

I don't have temp folder

versed flame
#

That's fine

livid cradle
#

so all these files other than vsconfig?

versed flame
#

yes, and keep .gitignore (Unity won't regenerate that)

livid cradle
#

done

versed flame
#

I forgot to check hidden folders 🤦

#

.vs can be deleted as well

livid cradle
#

well you can see which hidden folders I have

#

kk

versed flame
#

Now, you can start the project up again, wait for an eternity, and see if it still adds the script twice.

livid cradle
#

might take two eternities 👴

versed flame
#

If this doesn't fix it, then I am at a loss for what to do next.
If it's project-breaking, you need to move the question to #💻┃unity-talk

livid cradle
#

it's a nuisance cause I have to remove one script everytime

#

other than that

versed flame
#

yeah I've never experienced that

#

Ah one thing - if you're not using a project root namespace, then one of your classes could be causing a conflict, but I believe Unity would message that in a warning.

#

conflict due to identical name

livid cradle
#

I have not spent time to learn about namespaces yet

#

it still happens :/

versed flame
versed flame
#

Is it different if you add it via Add Component in the UI, rather than drag-and-drop?

livid cradle
#

just scripts

#

and only drag and drop

versed flame
#

Screenshot your Unity Version in the title bar

livid cradle
#

i been on this a few days

#

it only started to happen 1 or 2 days ago

versed flame
#

Did you upgrade the project to the latest Editor version?

livid cradle
#

yes

versed flame
#

I see. They have introduced the error at some point.

livid cradle
#

but the problem didn't start happening immediately

versed flame
#

You should log in and post about your experience, so that they realize it also affects 2021 LTS

livid cradle
#

will do

versed flame
#

Or perhaps create a new ticket. I will ask a mod.

livid cradle
#

if I can finish this last crucial functionality for my game

versed flame
#

If you're close to finish, that's great!

livid cradle
#

I am pretty near the "end"

#

a lot of polish is missing but the core is almost done

versed flame
#

Very good. This might not be a big issue for you then.

livid cradle
#

it's mostly just a nuisance

versed flame
#

I give no guarantees, but if I can spare some time I might come up with a scriptable solution to remove duplicate scripts

livid cradle
#

I could just start adding scrips from add component instead of dragging it

#

the workarounds given on that link work

versed flame
#

That's also good practice.

#

Good luck, dude 🙋

livid cradle
#

thanks! I hope I can figure it out

#

I saved the hardest part for last haha

versed flame
#

Which part is that?

livid cradle
#

You know space invaders, it has those shields/barriers that take progressive damage depending on where they were hit

versed flame
#

How do you want it to work?

livid cradle
#

as close to the original as possible

#

I have one idea how I might solve it though

versed flame
#

I can't recall if I've played that specific game actually

livid cradle
#

unless you were in the arcades back then or emulated it somehow I'm not surprised

#

but the way I was going to solve it was split the barrier sprite into many smaller ones, then try and piece them all together in the editor to look like the full barrier again

#

and each little piece gets a collider so only certain parts get destroyed

versed flame
#

Ah you want the shield to be based of separate components, which can fail

livid cradle
#

that's the only approach that makes sense to me

versed flame
#

is this 2D or 3D?

livid cradle
#

2d

versed flame
#

How does it look?

livid cradle
#

the barrier?

versed flame
#

yeah

livid cradle
#

this is the script I made

#

not script

#

sprite

#

here's how it looked in the original game

#

you can see how the barrier gets destroyed progressively

versed flame
#

So there's a forward barrier which progressively deteriorates

livid cradle
#

yeah but the player can also shoot it

versed flame
#

kind of like the steel bricks in Death Race

livid cradle
#

Perhaps

#

But yeah

#

I think I'll change the barrier from 32x32 to 64/64

versed flame
#

the player can damage the barrier?

livid cradle
#

and split it up into idk, 8x8 cells or smaller

#

yeah

versed flame
#

hmm

livid cradle
#

I try not to make other people solve my problems too much, if I can't implement it well I def will ask

versed flame
#

I have one idea

#

The barrier could be split into objects which can be removed
Add decals from weapon fire.
When the barrier is hit, it will register whether it came from North, East, South, or West. (but in vector logic)
By using the direction of the surface hit (surface normal).

Based on which side it was hit from, remove barrier objects from that direction.

#

A bit crude. I'm sure someone has a better one 😅

livid cradle
#

yeah somewhat what I was gonna do

#

but since the sprite has to degrade progressively, the collider also has to change

versed flame
#

When one of the 4 health pools is depleted, the damage has to be redirected to one which is not.
With a health system, several shots are required to remove each object.

livid cradle
#

ah

#

in the original one shot removes a part immediately

versed flame
#

maybe you want that then :)

#

but it would open up variation with Weapons

livid cradle
#

indeed

#

my project is somewhat extendable

#

you can look through it if you want I have it public on github!

versed flame
#

As for the collider.
Use one collider for each object.
Set them to a layer named "Barrier" or something.
Make them not collide with one another (in the Collision Matrix)

And instead of having one health pool for each object, you can use the wonder of static

#

Are you familiar with how static works?

livid cradle
#

somewhat yeah

#

my object oriented knowledge is weak, my muscles were with functional programming

versed flame
#

The script on each object should have a void OnCollisionEnter, which detects if it was hit, and from which direction.
You can use a Dictionary<Vector2,HealthPool> to match surface direction (normal) with the health pool for each direction.
And if the health of that particular pool is 0 is lower, choose another, based on whatever

#

Static is collective consciousness.

#

All the instances know about the statics

#

And there is only one of each static

#

So instead of the health pools being attached to the objects,
you will have 4 static HealthPools
Or for simplicity: floats that represent Health

#
private static float[] _healthPools;
private static Dictionary<Vector2, float> _poolDirections;
private static bool _initialized;

void Awake()
{
    if (!_initialized)
    {
        _healthPools = new float[4];
        _poolDirections = new();
        _initialized = true;
    }
}
livid cradle
#

wait yeah you're right!

#

D:

#

it matters if it was shot from below or above

#

yikes

#

this is even harder than I imagined

versed flame
#

Not really

#

sec

livid cradle
#

I mean

#

I have to do the sprite work for each section that can be destroyed

#

and for both directions it could be destroyed by

#

in case you're curious

versed flame
#
private void OnCollisionEnter2D(Collision2D collision)
{
    Vector2 direction = collision.GetContact(0).normal;
    Debug.Log(direction);
}
#

Actually, there's a bug with OnCollisionExit's direction output
so I'll give you a copy of my basic physics based ground check.

livid cradle
#

I'm dong the sprite right now anyway

#

so no rush

versed flame
livid cradle
#

makes sense

#

the difficulty isn't as much the collision, more how I want to split up my sprite

#

and how I want do do the sprites themself

#

hm

#

no

#

I think I have to do it different

#

Alright

#

I think I have a sprite solution that doesn't depend on direction at all :D

versed flame
#

I'd like to see how you solve that :)

livid cradle
#

It'll be a lot of sprite work

livid cradle
#

my initial idea didn't pan out exactly but your input of the health pool might give me some other idea

versed flame
#

Scripts added twice (Editor bug)

livid cradle
#

@versed flame I got it working 90% how I want to

versed flame
livid cradle
#

well, so far only the pixels that actually got collided with get destroyed

#

gotta work out a way to destroy some surrounding ones with a semi random feel

livid cradle
#

I was gonna do it with circleCasts

#

from the origin pixel

versed flame
#

Alright.
What I was thinking is you can get a random direction from the point of origin to the point within the circle, thereby pointing outwards in a random direction.

livid cradle
#

makes sense

#

but it gets one random point only?

#

the destruction can't be too random though

versed flame
#

Well yes, so if the direction doesn't lead anywhere, you'd just try again

livid cradle
#

like the immediate pixels next to the origin pixel should be destroyed

versed flame
#

not a great solution

livid cradle
#

creating an impact zone

#

and then some outter ones that aren't immediately connected as well, these should be more random

versed flame
#

Actually, if you want a random direction, it would be better to simply make 4-8 vectors inside an array, and get a random array element

livid cradle
#

it's not a random direction so to speak

#

I'll see if I can get my idea to work and if it does I'll let you know

#

can a circle collider even detect multiple hits at once

versed flame
livid cradle
#

if I can't figure out a working solution sure thing

versed flame
#

You can indeed get all the hits.

livid cradle
#

hold on, I'm a lil confused

#

wait nvm

#

the thing is though, does it contain everything within the circle or just whatever gets hit on the circle outline

versed flame
#

You can test that.

livid cradle
#

i hate how you have to write it yourself if you want to see the specific raycast

versed flame
#

They are changing that in 2022 or 2023

livid cradle
#

cool news

livid cradle
#

I'M

#

done

versed flame
#

What solution did you end up with?

livid cradle
#

I have a parent object with a script that I give a sprite to, the script reads the dimensions of the sprite and then loops through the sprite looking at each pixels alpha layer to decide whether or not to instantiate an object or not

#

calculate the position of the object and build a representation of the sprite with individual objects that all have their unique colliders

versed flame
#

that's quite elegant

livid cradle
#

On collision the individual pixel performs 2 circle casts, a smaller one and a bigger one. the objects caught by the smaller one get destroyed immediately and the ones hit by the larger ones get destroyed based on a random range of 0 to 15, if it's larger than 15/2 it gets destroyed

#

now I have to finish some loose ends, handle a game over, make a starting screen, implement resetting my game without reloading my scene

#

etc

#

get my animations working, implement sounds

#

then it's finished

versed flame
#

Very good. If you release it on itch.io or anything, feel free to DM me the link.

livid cradle
#

It will be there

versed flame
#

Good stuff.
Remember to add comments, so you know what the code does in 2 weeks.

livid cradle
#

yeahh.......

versed flame
#

xD

#

Perhaps you'd like to see an example

#

(I'm having trouble finding a good one xD)

#

This is my most fresh example of runtime code
https://gdl.space/dojabahuha.cpp

I made it readable with some Enums and descriptive method names, plus comments.
Not a great example, but it's something.

livid cradle
#

I am a chronic non commenter