#archived-code-general

1 messages ยท Page 112 of 1

lofty pewter
#

I cant get it to work

regal violet
#

Something like this

ashen yoke
#

i dont see the code where it doesnt work

lofty pewter
#

im a noob bro

ashen yoke
#

i know

lofty pewter
#

I don't understand how to set it up

ashen yoke
#

do something, show the code of that something

lofty pewter
#

bruh what

ashen yoke
#

write the code for the coroutine

#

show it, what exactly in it doesnt work

#

there is nothing for me to work with

#

you didnt write any coroutine code to tell you "this is incorrect"

regal violet
#
StartCoroutine(waiterAddLine());
 
IEnumerator waiterAddLine()
{
  mCanAddLine = false;
  yield return new WaitForSeconds(Utils.ADD_LINE_UPDATE_TIME);
  mCanAddLine = true;
}```
#

Something like this should do the job

lofty pewter
#

this is as far as i get without getting lost

ashen yoke
#

alright

knotty sun
ashen yoke
dusk apex
lofty pewter
#

I don't know where to put what

ashen yoke
#

you see the yield return ?

lofty pewter
#

yeah

heady iris
#

you need to modify the UVs before they're used to calculate colors

#

oops, I was scrolled way back

#

solved :p

ashen yoke
#

so a coroutine will suspend its execution on each yield

#

then it will continue from that exact place

#

so where do you put it?

dusk apex
heady iris
#

I just forgot to scroll down :p

lofty pewter
dusk apex
ashen yoke
#

the code you want to execute

lofty pewter
#

under the yield?

ashen yoke
#

right

lofty pewter
#

okay

ashen yoke
#

can you picture what is happening?

lofty pewter
#

yeah

ashen yoke
#

๐Ÿ‘

lofty pewter
#

So wait hold on

#

like this?

#

well i have one more thing

#

I need it to only work ontriggerstay

ashen yoke
#

that wont work

#

return it back to the way it was

lofty pewter
#

okay done

ashen yoke
#

look at the code above, and try to understand what is happening

#

you launch a coroutine once, it waits for 5 seconds

knotty sun
ashen yoke
#

oh and you dont have your IDE configured

#

@lofty pewter !ide

tawny elkBOT
#
๐Ÿ’ก IDE Configuration

If your IDE is not autocompleting code
or underlining errors, please configure it:

โ€ข Visual Studio (Installed via Unity Hub)
โ€ข Visual Studio (Installed manually)

โ€ข VS Code*
โ€ข JetBrains Rider
โ€ข Other/None

*VS Code's debugger plugin is unsupported.
We recommend using VS or Rider instead.

ashen yoke
#

before everything else config your ide

#

this whole method you wrote should be red from errors

lofty pewter
#

okay done

ashen yoke
#

ok now step back and describe the sequence of events that you want to achieve

#

i.e. Press E on door, wait 5 seconds, it slams

lofty pewter
#

am i getting closer

ashen yoke
#

yes

lofty pewter
#

well thats good

ashen yoke
#

dont forget that OnTriggerStay is fired every frame

#

and you are using GetKey which is also fired every frame

#

while you hold the key

#

as a result you are launching many coroutines that will interfere with each other

lofty pewter
#

So

#

OntriggerEnter?

#

and a keydown?

ashen yoke
#

or GetKeyDown, or StopCoroutine before starting a new one or some bool, there are lots of options

lofty pewter
#

can i use GetKeyDown with OnTriggerStay?

ashen yoke
#

simplest is a guard bool

lofty pewter
#

Or should I switch it to OnTriggerEnter

#

okay

#

i dont know what that is

ashen yoke
#

GetKeyDown will return true only on the frame the button was pressed

#

you have to "guard" some block of code from executing twice

lofty pewter
#

okay

ashen yoke
#

for that you use a bool to store if it was called already

#

and before running that block you check the bool

lofty pewter
#

okay

#

I don't even know where to start with that

ashen yoke
#

declare a bool

lofty pewter
#

okay

ashen yoke
#

name it for the purpose of it

lofty pewter
#

I did?

ashen yoke
#

wasDoorSlammed

lofty pewter
#

okay done

ashen yoke
#

now use it before calling the door slam

#

to ensure that it was only slammed once

lofty pewter
#

so if statement?

ashen yoke
#

yes

lofty pewter
#

okay

#

Do i need to change it to true or

ashen yoke
#

this will still launch coroutine itself

#

move the check to the coroutine start instead so you only ever start 1 coroutine

lofty pewter
#

like this

ashen yoke
#

yes, now you have to picture what exactly happens with that bool

#

because bools initialize to false

#

you dont need my help anymore the rest is just using logic

lofty pewter
#

like this?

#

oh shit it worked

#

thank you @ashen yoke

worn holly
#

so, is there a reason as to may why any mobile-related code isnt working for me? I tried doing a simple:

void Update()
{
  if(Input.touchCount != 0)
  {
    (and then i instantiated some random object just to have some visual response)
  }
}

and even that isn't working.
Yes i have switched platforms.

can someone help me on this?

vagrant blade
#

Did you actually test it on your device?

faint tree
#

anyone know how to fix VS when right mouse options are missing? like find references etc

#

moved computer and its caused so many issues

shrewd roost
#

can't figure this out. newer to events so sorry if this is trivial. anyone know what's wrong?

#

here's the other code snippets. they have the same overloads so idk what to do. the error doesn't make much sense to me

latent latch
#
EventManager.OnMinionDeathEvent += (IPlayable sender) => AdjustMinionpositions(sender)```
#

What you have would work if it was a void, but you're sending a param of type IPlayable

shrewd roost
#

now it says this. i am looking at a game's source code and trying to apply things and learn so i'm pretty in over my head here

somber nacelle
#

show the declaration for EventManager.OnMinionDeathEvent

shrewd roost
leaden ice
#

You need a MinionDeathAction whatever that is

shrewd roost
#

oh man you're right lol. i had an old method called OnMinionDeathEvent that it was looking at. I didn't realize the name i typed was wrong, and since the method existed it wasn't popping up a "that doesn't exist" error so i was getting confused. thanks

willow relic
#

HI everyone Im making a clicker game and ive got these auto upgrades where (once bought) it will auto make money and Item to sell and iive come to an issue with saving, im able to save how much money and so forth with playerprefs but when it comes to relaunching the game the functions of those auto upgrades wont start until bought again. I was wondering if someone would be able to help me figure out a way to save the Amount of upgrades bought and run those functions (if previously bought) once you load the game again. Bassicaly im wondering if you can save the function with playerprefs

dusk apex
#

How are you determining if those upgrades were bought already? If you haven't, maybe have some enum flag represent the upgrades and save/load that during OnEnable.

willow relic
#

there is a purchase log that increases with every Shop bought and keep track of how many is bought

cosmic rain
willow relic
#

Ok thank you ill give it a go

west rampart
#

Ultimately I want to have a trail of crabs that follow behind the player

#

I just cant math rn

leaden ice
west rampart
#

"'Transform' does not contain a definition for TransformPosition"

leaden ice
west rampart
#

Ah ok, I tried it:

#

But unfortunately the crabs just stack on top of each other

leaden ice
#

I honestly have no idea what I'm looking at here

#

Wait is this in 2D?

#

If it's 2D you want Vector3.left

#

Not back

west rampart
#

Yea 2D game. Think about it as if it were snake

leaden ice
#

Or down

#

Depending on how your sprites are

west rampart
#

I'll try

#

I think I have to use CrabTransform.down / left

#

right?

#

Instead of Vector3.down

leaden ice
#

Definitely not

#

It's confusing to me what the following thing is and the thing being followed

#

PlayerTransform.TransformPoint if the crabs are following the player

#

Your code has no mention of a player so I'm confused

west rampart
#

so CrabPositionsList is the thing I want to follow because I want each crab body to follow the one above it rather than the player.
CrabPool is the body of the crab which follows.

#

the player transform is index 0 in the CrabPositionsList

#

Here's the full function:

leaden ice
#

so CrabsPositionList[i].transform.TransformPoint(Vector3.left * offset)

west rampart
#

I'll comment out the rotation and try

leaden ice
#

and the rotation should really just be like

crabPool[i].transform.right = crabPositionsList[i].transform.right;``` I assume - Unless you're doing something odd beisde having them just look the same direction
west rampart
#

Going to run this. Btw crabBodyOffset is currently 8 will try messing with that

#

Changed the offset to higher value like 20 and I got this:

leaden ice
#

can you show the hierarchy? And what are the z positions of everything?

#

and what is the camera angle

west rampart
#

sure 1 sec:

leaden ice
#

or... the red crab in the middle perhaps?

west rampart
#

Oh sorry that's the butter it's a hazard im working on you can ignore it

#

the player is the red crab in the middle

leaden ice
#

at least the position

west rampart
#

Yea the position seems ok but they act weirdly

#

the goal is to have something like snake without the grid constraints

leaden ice
#

it looks like the spawned crabs are also children of the main crab?

west rampart
#

They are not

leaden ice
leaden ice
west rampart
#

Right above it is the PlayerCrabHead

#

which is the player

#

Crab body is an empty @ 0,0,0

leaden ice
#

what is CrabBody?

west rampart
#

it holds all the crabs that are pooled

leaden ice
#

wait I'm also seeing that... all of this seems to be happening inside of a canvas???

west rampart
#

Yea it's a 2D game

leaden ice
#

2d games should not be made on a canvas

#

canvases are for UI

#

2D games should be made using SpriteRenderers

west rampart
#

Oh

#

I have it this way because I needed to do a texture render

#

Anyways Im sure there's a way to solve it

#

I had it working before when I was moving the player

#

Here's the old code

leaden ice
#

it's unclear to me what the desired crab rotation is though

west rampart
#

it should be the same as the player

west rampart
leaden ice
#

because in that case the crab is moving

#

so there is a concept of "where it used to be" that the previous crab can follow

#

when rotating, all you have is the rotation

#

so the other crabs can only... do what they're doing in the one I pointed to as being mostly correct.. or do that but with some "lag"

spare island
#

Is there anybody here familiar with NodeCanvas? For some reason this part of the tree always repeats even if the right side times out
(It doesn't matter if I change it from Until Success to Failure)

dusk apex
#

Looks like visual scripting? ๐Ÿค”
There's a Bolt server, maybe you can ask them there #763499475641172029

west rampart
spare island
#

visual scripting controls the how, behavior trees are just flow control and there's not really a relevant channel to that

dusk apex
severe falcon
#

anyone know why my scriptable object doesnt show up in the create menu?
[CreateAssetMenu(fileName = "New Spell", menuName = "Spells")]
public class spellScriptableObject : ScriptableObject
{

jagged pilot
#

Hi everyone, I want to instantiate several copies of a ball prefab I have to fill up the space I have outlined in yellow. However, the actual shape is shown in orange. Is there a way to randomly generate bunch of ball prefabs so that it fills up the yellow space?

leaden ice
jagged pilot
#

It's a cube and I just used other shapes to make it look like a trapezoid using colliders

severe falcon
tall coral
#

So, I'm using Json to store data. I want to create a system where I create a dictionary with a gameobject type as the first parameter and the amount as the second parameter, so I can create a randomized list of enemies for the next wave basically. I want this to save so that a player can't get this list, be dissatisfied, and close the game / reopen to get a new list of enemies. However, from what I've seen it's super complex and annoying to save dictionaries through Json. Is there an addon I could use or something to make saving dictionaries easier?

potent sleet
#

reference types should prob be the last thing you'd wanna try serialize

tall coral
#

So I should create a lookup system

potent sleet
sweet perch
west rampart
sweet perch
potent sleet
#

also use Newtonsoft instead of JSON utility

dusk apex
tall coral
# potent sleet does it matter btw if player changes those values ?

yes, it's the base of the game. Basically risk and reward, the player can choose to add more enemies to get a higher coin multiplier at the end to progress faster. however, it's a random enemy that is chosen, with it being more likely to add harder enemies with higher score multipliers. So sort of like blackjack, you want to get as much as you can fight without overdoing it.

dusk apex
ashen yoke
#

nope, just as is, maybe with a wrapper

tall coral
potent sleet
#

read the json from web

#

using UnityWebRequest

ashen yoke
#

here he uses a custom class to wrap it

#

but you dont need to

#

you can serialize in place in the mono

sweet perch
tall coral
potent sleet
#

or you can use something like a database

#

FireStore/Firebase

#

Lootlocker

#

mongodb

#

etc

tall coral
#

That sounds way out of my skill range, is this because there's still the chance of someone de-encrypting to modify the chosen enemies?

potent sleet
leaden ice
tall coral
#

Yeah, but with encryption you'd have to know the encryption key, no?

potent sleet
#

unless they don't know it's a json file you can obfuscate it storing as byte

#

or som

potent sleet
#

nothing is encrypted

#

you just store and retrieve data/json remotely

#

with API calls

#

no one can touch your file remotely

tall coral
#

Nono I'm saying my save system has encryption already so there shouldn't be an issue with saving locally

potent sleet
#

ig , your game can be decompiled and find the encryption used

#

encryption code should generally be on Server Side

#

you just get a token usually

tall coral
#

Ah, that's true. Well is there somewhere you suggest I start for storing data remotely? Sounds like a lot to figure out as i've never done anything even web-related

potent sleet
#

learn to store to a local DB first and then do the same thing remotely

leaden ice
#

Is this a multiplayer game?

tall coral
potent sleet
leaden ice
potent sleet
tall coral
#

wait wouldn't storing data remotely mean that you'd need internet to play the game lol

leaden ice
#

yes

tall coral
potent sleet
#

you can still store it locally but yes you'd need a connection to eventually send/retrieve the DB

leaden ice
potent sleet
#

fr

tall coral
#

yeah I was just thinking about that

leaden ice
#

who are they really cheating, besides themselves, in that case?

tall coral
#

the fact that the only person effected by cheats is the player so

#

yeah

potent sleet
#

just don't put online leaderboards :p

tall coral
#

true enough. If I go through the effort for that I can just learn remote data storage then.

potent sleet
#

literally storing sum like .dat or .bin
throws of most regular players anyway, they wouldn't know to mod that

tall coral
#

although I doubt this game is even going to be published honestly

potent sleet
#

why are you crossposting

#

and not code related

hallow plume
#

sorry

#

just want some advice:<

tall coral
#

there's lots of videos for this on youtube

potent sleet
tawny elkBOT
#

๐Ÿง‘โ€๐Ÿซ Unity Learn can offer you over 750 hours of free live and on-demand learning content for all levels of experience! Make sure to check it out at https://learn.unity.com/

lean sail
hallow plume
#

sorry my bad

tall coral
potent sleet
lean sail
potent sleet
#

I'm saying common player/user won't know what that file is

#

you can save a whole json as .bin for ex, and someone doesn't know what's in it unless they looked deliberately

tall coral
lean sail
#

hiding it as a different file extension wont do anything then, if someone breaks your encryption/finds your key, they're going to be able to find the save file lol

potent sleet
#

that's a lot of effort for a solitaire type game

lean sail
#

id say just keep it at encryption, leave it be, and save your mental by moving on

#

yes, or as its called: encryption

tall coral
lean sail
#

Changing the extension/file name to be something you hope the user wont find is irrelevant

#

i wouldnt even suggest it, its probably one of the easiest things to find

tall coral
potent sleet
#

lol wrong card game

lean sail
#

it seems you're suggesting to make your own encryption algorithm, but are referring to it by "making it non-readable". That is literally what encryption is

tall coral
#

I was saying the idea is based on the idea of blackjack, that's all

potent sleet
#

gotcha

tall coral
#

risking it without going too far that you end up getting yourself killed essentially

lean sail
#

custom format? are u suggesting that he just store it with nonsensical words. i dont know why you would opt for an intentionally worse method thats harder to implement

#

encryption is like the easiest thing to implement, understanding the theory and everything is the harder part.

tall coral
#

but that's harder than and less reliable than XOR encryption so there's really no point

lean sail
#

why opt for a worse method though

tall coral
#

how is XOR worse than binary encryption?

lean sail
#

i didnt mean for u, i meant binary is just worse

#

binary isnt even encryption lol

random crane
#

I dont know why unity says theres no closing bracket when there is. Pls help

tall coral
#

harder to implement manually from what I know

somber nacelle
tawny elkBOT
#
๐Ÿ’ก IDE Configuration

If your IDE is not autocompleting code
or underlining errors, please configure it:

โ€ข Visual Studio (Installed via Unity Hub)
โ€ข Visual Studio (Installed manually)

โ€ข VS Code*
โ€ข JetBrains Rider
โ€ข Other/None

*VS Code's debugger plugin is unsupported.
We recommend using VS or Rider instead.

lean sail
#

you can directly convert from binary to whatever format the data was initially in.
If the file was saved in binary, the user doesnt even need to convert it, they can just paste sections around until one loads in the game.
If you suggest they swap around bits, then thats just a self made encryption

#

as secure as you can get on the client side
yea, no.

potent sleet
#

and configure your IDE

lean sail
#

encryption methods like RSA, DES, AES
if the key is just going to be stored in the game files then theres not really a great way since there are methods to see the code. But without the key, the file is completely unusable. Itll be practically impossible for anyone to figure out what values they can just write in

#

storing the key itself is another problem, especially if the entire game is local and can be played offline. But definitely relying on hiding the key + an encrypted file is way way way better than writing a random file extension/using binary

somber ether
#

if a game is singleplayer/offline then forget the protection, its better to be open

lean sail
#

the difference is that encryption will stop anyone messing with the save file and being able to actually accomplish something. They would need to open up the code and see what the key actually is and would have to know what encryption method u are using.
With what you suggested, the player can just mess with the save file and do anything

hidden citrus
#

could you use cloudsave to store your aes keys

somber ether
#

Why? its offline. So what if someone hacks their local score, they are having fun in their own way

#

At least they are even playing your game

lean sail
# hidden citrus could you use cloudsave to store your aes keys

u could store the key on a server, but you cannot send the key to the client to have their client encrypt the data. That could be picked up by some tools that i forget the name of. I believe the client would have to send the plaintext, and the server sends back the ciphertext

lean sail
swift falcon
#

I have a question...how expensive is it to add/remove script components? I am making an ARPG, and to handle DoT and debuff effects, I'm just attaching a script to the enemy called like "BurningEffect" that deals damage over time, then removes itself after a while...is there a better way to do this or is this more or less the standard practice?

somber ether
lean sail
hidden citrus
#

i was actually thinking about this earlier today, you think the added step of encrypting your data does deter people who would already go that far to manipulate a save file for example

lean sail
#

Mods arent the same as just editing a save file, at all

somber ether
#

Its a local game, whats the harm in someone editing a save?

hidden citrus
#

Okay, so I guess a good idea would be to be sneaky with the key

#

hide it in the sound manager or something

somber ether
#

You want people to play your offline game yea? Those who want to play legit are going to have fun, those who want to save their time and change some stuff will either go as many steps as it takes to break what you think is unbreakable, or just uninstall the game because they cant edit it.

lean sail
#

If the key isnt random, you can swap out the files.
And reverse engineering encryption techniques is like impossible, finding the key is going to be harder than finding a binary file of save data.
Reverse engineering a binary format literally just means converting from binary to string or int or whatever the data is

lean sail
lean sail
somber ether
lean sail
#

again, thats your opinion on it

#

anyways, kinda rude to just step in on a conversation about encryption techniques to just say "dont encrypt lol". Im not here forcing them to do it, we're just talking about encryption.

somber ether
#

Well im putting it out to him that he should not and does not need to go through all this stress if its an offline game, especially if the game isn't even complete/has no players

lean sail
#

Every single game that ive edited save files for, ive lost interest in the same week

hidden citrus
#

I kinda like it. Just feels a little more professional to just put the extra effort?

lean sail
#

encryption really isnt even effort to implement, its like 3 lines of code lol

somber ether
#

Properly building as IL2CPP is more pro

lean sail
#

regardless the logic of "i want people to be able to edit their saves" is a personal choice. Telling someone they shouldnt because YOU think its a better choice is ridiculous.
Add a modding feature if you'd like ontop of it

#

having players accidentally nuke their save file isnt fun either

somber ether
#

Specific to this situation, I dont presume youd even get a player to play your game that wants to hack a solitaire game. Itll be much to even get a normal player to download that app lol

somber ether
lean sail
#

from what he said, it wasnt solitaire but just a comparison

#

๐Ÿคทโ€โ™‚๏ธ you're literally the one who brought up modding so dont ask me lol

somber ether
#

Ah, I saw him mention solitaire sorry

somber ether
somber ether
#

Exaggerated. But just the fact of trying all sorts of things to protect all corners

lean sail
#

its nice especially if you plan to develop for the future. If the game gets popular and they add a leaderboard system then not having it encrypted in the first place is a huge problem

somber ether
tall coral
#

Lol I love broken telephone, I initially compared the enemy spawning to blackjack. got interpreted as a solitaire game. It's neither, it's a survival shooter. I just compared one feature to blackjack.

lean sail
cosmic rain
random crane
#

Im trying to change the image of the hearts in the top right to a red heart image I have set to variable heart_img. How do I do this without getting an error?

tall coral
cosmic rain
#

Perhaps

tall coral
# somber ether thats when you do it. not now

what's wrong with doing it now? If I decide later I don't want it for whatever reason, it's easier to remove than add later. Currently I think it makes sense that if someone wants to turn my game into whatever creative mode shooter they want, they shouldn't be a 10 year old that goes, "Oh save file. alright gonna just give myself whatever, such fun", I mean the file I'm encrypting runs the core mechanic of the game. I'd prefer if every player couldn't change all of the gamedata in a few clicks.

potent sleet
#

remove Image image =

#

or set Image componet first then do image.sprite = myspriteorwhatever

somber ether
tall coral
lean sail
somber ether
tall coral
void basalt
somber ether
void basalt
#

what's the issue with people modifying singleplayer state data?

tall coral
void basalt
#

If you want it to be harder, then binary serialize it

#

encrypting this is the worst way to go about it

random crane
#

why wont debug.log or console.writeline work?

tall coral
somber ether
tall coral
#

anyone who does, whatever. Go ahead at that point.

void basalt
#

Your mindset makes no sense

lean sail
tall coral
#

I've cheated through changing game files. I do it lots. I don't bother going through encrypted files. I think my mindset makes perfect sense based on personal experience

void basalt
#

What does it matter if someone cheats on a singleplayer game though? Everyone does that

somber ether
#

Its a Unity game in the first place XD, can convert your game to a project -> replace the guns with bananas -> recompile the game -> more fun

tall coral
void basalt
#

Your thoughts are not in the right place pal

random crane
#

@lean sail I did

lean sail
somber ether
void basalt
#

I'm not being rude, I'm just being real.

#

If he wants to obfuscate it, just binary serialize it and stop messing around with local encryption

random crane
tawny elkBOT
#
๐Ÿ’ก IDE Configuration

If your IDE is not autocompleting code
or underlining errors, please configure it:

โ€ข Visual Studio (Installed via Unity Hub)
โ€ข Visual Studio (Installed manually)

โ€ข VS Code*
โ€ข JetBrains Rider
โ€ข Other/None

*VS Code's debugger plugin is unsupported.
We recommend using VS or Rider instead.

tall coral
#

It's not like I'm putting a week into this

void basalt
#

alright man

#

best of luck

lean sail
#

is binary serialize even secure?

#

i havent looked much into it

void basalt
#

when you're not using binary formatter it is

tall coral
#

yeah binary formatter is a no-go

hidden citrus
#

You think it would make more sense to build/test my android project right to my own physical device or just emulate through android studio?

somber ether
#

No need XOR, build as il2cpp, save file as dlc.bin

somber ether
random crane
#

It says I have to modifie visual studios in package manager to update the IDE but its not in there

potent sleet
#

there are more important ones to do before it

#

also it would be under InProject not MyAssets

random crane
#

the only other step it says to do before that is this which I already did

granite nimbus
#

I'm trying to figure out how to create package.json via code, and I have troubles understanding how do I generate the

"dependencies": {
    "com.[company-name].some-package": "1.0.0",
    "com.[company-name].other-package": "2.0.0"
 }

assume that I already have an array of objects like this:

public struct PackageNameVersionPair
{
    public string name;
    public string version;
}

how do I actually convert it to right json representation? ๐Ÿค”

potent sleet
random crane
#

how do i add that?

granite nimbus
void basalt
#

It's highly unlikely that unity would allow things to break between updates

#

especially the API

granite nimbus
#

I mean, this doesn't tell anything new. the issue is that jsonutility generates the pattern like this

"dependencies": {
    "com.[company-name].some-package": "1.0.0",
    "com.[company-name].other-package": "2.0.0"
 }

from fields of an object. but I don't have fields. I have an array of keyvalue pairs

void basalt
#
{
    public string name;
    public string version;
}``` This aren't keyvalue pairs
#

If your structs are in a dictionary, then it's no different

granite nimbus
#

it doesn't really matter here. how do I generate json?

void basalt
#

I just linked you to a whole page dedicated to json in unity

lean sail
#

it does matter, you wont get the same pattern

void basalt
#

I still have no clue what you're asking

#

Your serialization data must be enclosed in a struct or class

#

that's the limitation of JSON.

granite nimbus
#

jsonutility translates
public string myField; with value of "myFieldValue"
to
"myField": "myFieldValue"

however, I don't have fields, since I want user to type in packages and names and I want to generate package.json from that

#

that's what I'm asking

void basalt
#

w a t

lean sail
#

kekwait are u making a game where the user builds their own game?

hidden citrus
#

hey cnfnbcn

granite nimbus
#

who said I am making a game in the first place?

#

I outlined what I want pretty clearly

void basalt
#

no, you haven't

hidden citrus
#

maybe instead of using jsonutility try using newtonsoft json? It easily writes to json with proper indentation

#

reads objects too

granite nimbus
void basalt
#

I don't think that's going to make much of a difference

lean sail
#

the indentation isnt the problem, they just dont have the data in the right format to begin with

granite nimbus
#

I am about to just manually write whole file instead of jsonutility. but I thought maybe there's non-roundabout way of doing this

cosmic rain
#

I think Newtonsoft package can serialize a dictionary as a json object(what "dependencies" end up being in Json).

granite nimbus
#

wait can't jsonutility serialize dictionary? let me try

cosmic rain
#

JsonUtility can't do that

#

No

granite nimbus
#

the problem is that I don't want any dependencies (by design)

cosmic rain
#

Then write a custom serializer ๐Ÿ˜‚

granite nimbus
#

that's what I'm about to do yeah

void basalt
#

@granite nimbusIf you're going to write your own serializer, do yourself a favor and skip text based parsing and just do binary serialization.

cosmic rain
#

They probably need it like that for unity to recognize it as a package manifest or something

#

Binary isn't gonna work

granite nimbus
#

yes, I just need package.json

#

I'll just do non-universal proprietary serializator for package.json only and it will do

cosmic rain
granite nimbus
#

they already exist in packages

cosmic rain
#

Ok, and how is the downloaded file created?

granite nimbus
#

no idea ๐Ÿ˜„

cosmic rain
#

I doubt they create it by hand every time...

#

Maybe they have some external tools for that they don't release.

unreal temple
#

Does anyone know how to read/write AnimationCurve.Keyframe tangent modes at runtime?

    //
    // Summary:
    //     TangentMode is deprecated. Use AnimationUtility.SetKeyLeftTangentMode or AnimationUtility.SetKeyRightTangentMode
    //     instead.
    [Obsolete("Use AnimationUtility.SetKeyLeftTangentMode, AnimationUtility.SetKeyRightTangentMode, AnimationUtility.GetKeyLeftTangentMode or AnimationUtility.GetKeyRightTangentMode instead.")]
    public int tangentMode { get; set; }

These suggested methods are all in UnityEditor.

void basalt
#

I've had the same issues with things relating to animation. Lots of useful stuff only available in the editor.

unreal temple
#

Turns out the "constant" tangent mode will have the tangent equal to either float.Infinity or float.NegativeInfinity depending on whether it's a vertical or horizontal constant

#

Behold!!!!

    public static void Invert01(this AnimationCurve curve) {
      var keys = curve.keys;
      for (var i = 0; i < keys.Length; i++) {
        keys[i].value = 1 - keys[i].value;
        if (float.IsFinite(keys[i].outTangent)) {
          keys[i].outTangent *= -1;
        }
        if (float.IsFinite(keys[i].inTangent)) {
          keys[i].inTangent *= -1;
        }
      }
      curve.keys = keys;
    }
random crane
#

@potent sleet Thank you so much for you help it finnally works

leaden tundra
#

Ok I have gone to almost every article online to see why this small little annoying bug keeps happening but for some reason even though I have the script disabled this trigger script keeps enabling another script that I have even though I have that proximity script clearly disabled

#

I will post both scripts on here to see if someone can tell me what im doing wrong

severe geode
#

what that hek hah
!code

tawny elkBOT
#
Posting code

๐Ÿ“ƒ Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

๐Ÿ“ƒ Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

lean sail
#

trigger events still work even if the object is disabled

leaden tundra
#

i tried disabling trigger as well

#

but that didnt work

quartz folio
#

Link large codeblocks using external services, as was mentioned in the bot message.

severe geode
#

why u dont use !code

tawny elkBOT
#
Posting code

๐Ÿ“ƒ Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

๐Ÿ“ƒ Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

lean sail
leaden tundra
#

Cartrig.GetComponent<BoxCollider>().enabled= false;

#

Cartrig.GetComponent<BoxCollider>().Istrigger= false;

severe geode
lean sail
leaden tundra
#

So what is happening at least what i think is happening

#

is that when the player gets parented to the car or firstperson player

#

its triggering the CarTrig still

#

even though the Car Enable script disables the script for CarTrig and the gameobject

#

nvm that wasnt the problem

lean sail
#

im honestly confused what the problem is, or what you're trying to do because these names are hard to follow

#

you say something is happening with CarTrig but you sent the script for CarProx which also has a on trigger enter

leaden tundra
#

CarProx is where most of the trigger events are* happening

#

Car Enable is the script where it is supposed to disable everything

lean sail
#

which object in this hierarchy actually has all of these components being used in CarEnable

leaden tundra
#

Car

lean sail
leaden tundra
#

The cartrig is used for the CarProx script

#

when the player gets close the car door

#

which enables the carenable script

#

which allows the player to press E

#

to enter the car

#

E also disables the Carprox script

#

then when pressing backspace

#

the Carprox enables again

#

and the player is un parented

lean sail
#

If CarTrig has the CarProx script, but CarEnable is on Car, then CarEnable wont be able to get GetComponent<CarProx>() because its not on the same object

lean sail
#

because CarProx would be referring to any triggers on the Car

hidden citrus
#

You might be thinking too literal about getting into and out of a car. You wouldn't really need to make the player a child of the the car if you just want to move the player to the location the car is at when you stop using it

#

you could just zap the player somewhere else, like object pooliing

leaden tundra
lean sail
#

yes but you said the CarProx script was on the Car

leaden tundra
#

yes

lean sail
#

so its not on CarTrig..

leaden tundra
#

yeah

#

both scripts are located in the car

lean sail
#

whats CarTrig even for then

leaden tundra
#

to detect if the player is by the car

lean sail
#

if CarProx is on the Car and not on CarTrig, CarTrig wont do anything

#

what components do u have on CarTrig

leaden tundra
#

just box collider

lean sail
#

yes so its not going to do anything then, its just a trigger with nothing on it

leaden tundra
#

but it works still

#

it just doesnt disable

lean sail
#

what doesnt disable

leaden tundra
#

the CarTrig

#

and CarProx

lean sail
#

Does anything else get enabled/disabled when you press E then?

#

and is Car Enable active when u do this

leaden tundra
shell scarab
#

what about this code would cause unity to hang?

public SpriteRenderer nodeObject;
private List<SpriteRenderer> nodeObjects;

private void Awake()
{
  actions = new Input().LevelBuilder;
  nodeObjects = new(20);
  for (int i = 0; i < nodeObjects.Count; i++)
  {
    nodeObjects[i] = Instantiate(nodeObject);
    nodeObjects[i].gameObject.SetActive(false);
  }
}

Vector2Int pos = (Vector2Int)tileMap.WorldToCell(Camera.main.ScreenToWorldPoint(mousePos));
switch (selected.mode)
{
  case 1:
  {
    if (nodes.Contains(pos))
      break;

    SpriteRenderer r = nodeObjects.Find(n => n.gameObject.activeSelf && n.color == Color.green);
    if (r != null)
    r.color = Color.yellow;

    if (nodes.Count > 0)
      nodes.Insert(0, pos);
    else
      nodes.Add(pos);

    SpriteRenderer s = GetNodeObject();
    s.color = Color.green;
    s.transform.position = (Vector2)pos;
    break;
  }
}
lean sail
hidden citrus
#

don't switches need a case default: in cs?

shell scarab
#

If there's nothing wrong with this section then my problem lies elsewhere, but I seriously doubt that.

lean sail
#

post the full context because its harder to suggest things when its solved somewhere else

leaden tundra
cosmic rain
shell scarab
lean sail
# shell scarab huh?

dont hide parts of the code, there seems to be a bit of missing context in here

shell scarab
#

I'm not hiding any parts of the code

#

I mean I guess I didn't include what method the switch is in, it's in this method:

private void Clicked(InputAction.CallbackContext context)
    { ... }
lean sail
#

yea so some parts are missing.. do you know if the switch statement is whats causing it to hang for sure

cosmic rain
shell scarab
#

what parts are missing???

mellow sigil
#

If nodeObject has this script on it then it'll freeze

shell scarab
#

it doesn't... I don't think. I'm reloading unity now.

cosmic rain
#

Use a debugger and save all of us some time.

shell scarab
#

i forgor VS debugger

sharp sun
#

Is there anyone familiar with lidgren that can help out with connecting server/client from within the same instance of the app? I just can't seem to get the client.Connect() call to do literally anything.

lyric oriole
#

Hey does any programmer mind if they help me with something
im trying to make a placement grid on a sphere anyone know how i should do it or any sources i could experiment and look over?

sharp sun
knotty sun
lyric oriole
sharp sun
dense cloud
#

Want to ask about jittery 2D movements caused by transform position

iirc transform ignores physics (e.g transform.position, transform translate)
This code that moves and object to the left when the left arrow key is held down

if (Input.GetKey(KeyCode.LeftArrow))
  {transform.position+= Vector3.left * speed * Time.deltaTime; }

produces stuttering/jittery movements on collision with a wall, but changing Update() the code is in to FixedUpdate() resolves it
Why is that?

#

Is it because the moving object is attempting to go through the wall, but the wall's physics is pushing it back?

#

Holy shit... that

#

was a shot in the dark

sharp sun
#

I believe Rigidbody.MovePosition can help you, though it might do the same thing?

#

Otherwise a Rigidbody.Sweeptest could work

dense cloud
#

but thanks for the help ๐Ÿ‘

cosmic rain
#

Generally, if you rely on proper collisions, you should move your object via physics as well.

topaz girder
#

Im a begginer can someone help with a small code

winged mortar
mossy shard
#

anyone help with navMesh? i got it going in my slopey field and it doesn't work at all when it has to chase the player, it keeps getting stuck and when i see it's path it sometimes paths to itself then goes back to me, but when my field is flat, it works no matter the situation, anyone knows why (i tried to change the navAgent settings and nothing seemed to work)

cursive gorge
cosmic rain
#

Help with what?๐Ÿค”

cursive gorge
#

client takes position delayed

cosmic rain
#

Okay?

cursive gorge
#

Thats a problem i guess?

cosmic rain
#

Did you expect a multiplayer game without latency?

cursive gorge
#

but is on localhost

cosmic rain
cosmic rain
#

At best, it sends a packet to your router, it routes it back to the PC. So there's at least 1-2 frames lost there. Then consider the fact that it probably processes the packets at fixed frame rate, making it wait for the next tick and there you have the latency.

#

At worst, it could be using a relay, sending your packet to Mars and back.

#

And considering your game is server authoritive, it doubles the latency.

#

Because the client also has to wait for an update from the server until it can move the character.

severe geode
cursive gorge
#

other than that, I still do things with the server

#

Healt raycast etc.

cosmic rain
#

Just moving your character on the client is sure way to lose sync between client and server.

heady iris
#

this is the moment where you take the red pill

#

actually

#

it's the moment you take an entire bottle of them

#

and then choke and go to the emergency room

#

i love multiplayer

#

it's so easy and straightforward (:

hybrid relic
#

or people gonna fly around

#

you just need to code in some lag compensation or use a addon

#

Smooth Sync is one i can instantly think of, that supports nearly every modern networking for unity

#

or Fishnet Pro as a replacement for netcode since that has all that already included

fluid lily
#

Is there any way to add to that menu? Maybe through static extensions?

#

I want a SetPosition(Vector2) type of thing so I can just hook in like this.

swift falcon
#

Hi guys. "item" in the line 59 switch (item.itemType) is coming back as NULL. I am trying to figure out why because this is the only line where this happens. Are the parameters in public void AddItem(Item newItem) messing it up maybe?

fluid lily
#

Item looks like a class, I imagine the "item" variable is null.

#

As even if itemType was default it wouldn't throw a null error.

swift falcon
fluid lily
#

Where are those two being called from? If something is setting it to a value between the two calls it wouldn't be null.

#

Or is AddItem the only place you are setting item?

swift falcon
swift falcon
trim schooner
#

if item isn't assigned anywhere, the first time you try to add an item you'll get a null ref error.

if (item == null) { item = newItem; return; }

#

before the switch

fluid lily
#

Yeah I also am assuming the code isn't reaching UseItem, which is why it isn't throwing null.

#

As it just isn't reached

trim schooner
#

you don't call it

swift falcon
#

ahh I see now

swift falcon
#

but from another script

trim schooner
#

no, you do not

#

there are 0 references

swift falcon
#

huh it works tho

trim schooner
#

Calling it from another script would still show a reference

swift falcon
#

your saying UseItem never gets called

trim schooner
#

VS is saying it isn't

severe geode
#

lmao

swift falcon
#

it is

#

cuz

#

ist working

swift falcon
trim schooner
#

100% does, I use it all the time

swift falcon
#

then how does it work

trim schooner
#

I'd be willing to bet you're calling some other method called UseItem(), not this one ๐Ÿ˜„

#

Go to the class where you call UseItem() .. hold ctrl and then left click it.. where does it take you?

swift falcon
#

I'm so confused rn

#

the debug shows

trim schooner
#

Show a screenshot of the debug

swift falcon
#

see

trim schooner
#

It's coming from line 69 on InventoryItemController

trim schooner
swift falcon
#

its on 69

swift falcon
#

Ahhh

#

@trim schooner I know

#

why

#

the method

#

is being called

#

with a UI button

trim schooner
#

Type in full sentences

#

Right, it's from an exposed UnityEvent

swift falcon
quartz folio
paper mirage
#

I want to represent a group of integers in the inspector. I think a serialized array is too clunky since it takes a whole line per int, and I'd like to avoid writing logic to parse a comma-separated string. Anyone know of any good alternatives?

leaden ice
#

You could write some custom inspector if you want to represent them in a different way graphically or something

paper mirage
#

I've considered doing it that way if there is no quicker alternative, because it's kind of out of the question to use one whole line of inspector space per int. The script would bloat up and take too much inspector real estate if I did it that way. It's a pain to edit as well, I don't like interacting with UI for adding and removing elements in the inspector.

leaden ice
#

I'd like to avoid writing logic to parse a comma-separated string
I think you're kind of overblowing how hard this would be too btw

#

it's like... 3 lines of code max?

thick socket
#

can you call a switch statement for grabbing player input like w/a/s/d

unborn sphinx
#

There are even builtin parsing methods for such tasks, right?

paper mirage
# leaden ice ^

The "I've considered doing it that way" part was a reply to the custom editor thing

thick socket
#
      if (Input.GetKey(KeyCode.A))
            rb.AddForce(Vector3.left);
        if (Input.GetKey(KeyCode.D))
            rb.AddForce(Vector3.right);
        if (Input.GetKey(KeyCode.W))
            rb.AddForce(Vector3.up);
        if (Input.GetKey(KeyCode.S))
            rb.AddForce(Vector3.down);

aka turn this into a switch

#

(code flow choice)

leaden ice
thick socket
#

ยฏ_(ใƒ„)_/ยฏ

#

figured it looks better and easier to read than a bunch of if statements

paper mirage
leaden ice
thick socket
#

yeah...that definately seems better thankks

#

didn't realize that was a thing

thick socket
quartz jay
#

So, i've created a damage script for a gun and when i shoot it debugs the name of the object the Raycast hits. then i created a target script for the enemies and gave it health value of 100f and my gun script damage value is 10f and in the health script i created a take damage with a (float amount) and did health -= amount and if health <= 0f then it should destroy gameObject but thats AFTER the damages falls to 100f which is after 10 left clicks
It works but when i do shoot an object with the enemy target script
the object gets destroyed instantly
even though my damage is set at 10f and my object health is 100f
anyone have a clue why this happens
i've even tried setting my damage to 1 but it still destroys the object instantly after i shoot it

unborn sphinx
leaden ice
leaden ice
paper mirage
unborn sphinx
leaden ice
# quartz jay

Input.GetMouseButton(0) returns true every frame while the button is held

#

so if you hold the button for 10 frames

#

the guy is deead

#

at 100FPS that's 0.1 seconds

#

even faster if your framerate is higher

thick socket
unborn sphinx
#

Talk about instakill

thick socket
#

guess I'll have to test and see thanks...its going to be a 2d dungeon crawler style

paper mirage
quartz jay
#

I see

#

thank you

unborn sphinx
#

Hey everyone. I hope for help.

Can I make methods with generic types to check for various enum auto properties?

TL;DR
I have a project that loads some minigames with certain properties. Each one is contained in a scriptable object, where each property is set via an enum or flag - so it is a simple dropdown choice in the inspector for the content makers. (all fine and dandy there)
Now my project group wants to load several games in parallel (i hate it, but ok...). Therefore I need to check game properties and load those that fit together.

I made several check methods in a Controller script, but found out, that all checks are pretty similar, if not identical - they only differ just in enum "name"/type. So I tried to write a method taking a Generic Type and checking the enum by the given type.
I spent some time (2-3hrs) researching far and wide, and the documentation says generic typing with enumerations isn't even possible.
But I thought maybe someone has maybe an idea, that doesn't involve code duplication (it's all unnecessary messy as it is, with parallel gameplay BS).

Here are some code snippets that might help you understand the problem. If it's unclear, I'll try to provide more. But the other code parts are pretty irrelevant.
https://gdl.space/xowahihace.cs
Please don't mind the code structure, It all needs overhaul anyway. It's hacky as it annoys me and I don't give it much attention.
I'd first try to make it generic and then come up with a cleaner code. (or If generic fails, rethink it anyhow...)

Thank you.

rain crater
#

Hey, how should I recalculate normals, to have them flat and not smoothed like this? The mesh is generated procedurally

paper mirage
leaden ice
#

if you just want to check if the enum value is a certain int regardless of the enum type, you can simply do:

if ((int)myEnumValue == someIntValue)```
thick socket
#
[field: SerializeField] public float CurrentHealth { get; set; }
VS
public float CurrentHealth```
#

I feel like there is a difference

#

but I need help understanding what it is lol

hexed gale
#

guysi dont know what this codes does , my player name is (Player) and my trap name is (Trap) im doing if the player collides with the trap the player will get destroyed , this is the code and i dont know this , i know a little :

private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.CompareTag("Player"))
{
Destroy(collision.gameObject);
}
}

hexed gale
unborn sphinx
# leaden ice if you just want to check if the enum value is a certain int regardless of the e...

well. currently I have lots of similar or identical methods just accessing the properties, comparing it with the next game to load, and returning true or false, if it matches. But so far I do it by one Method per property, even if they do the same... that causes loads of duplicate code.
What I want to achieve is a generic method, that would work for any Property (which is a certain type of enum), as I have many different ones (despite all bing just ints in the end). That way I could write

checkProperty<Orientation>(currentGame);
or
checkProperty<Genre>(currentGame);
etc

instead of

checkOrientation(currentGame);
or
checkGenre(currentGame);
etc
leaden ice
#

what do you mean by "comparing with the next game"?

unborn sphinx
#

it's a game package

leaden ice
#

yeah but what kind of comparison are you doing and why

unborn sphinx
#

2 games (for wahtever reason) shall be loaded on screen. After some time a 3rd is loaded (the "next" one)
and it shouldn't be the same as before

#

in genre, screen orientation, key mappings and much more

paper mirage
unborn sphinx
leaden ice
unborn sphinx
late lion
paper mirage
unborn sphinx
leaden ice
#

sounds like it needs further refactoring ๐Ÿ˜‰

unborn sphinx
#

I'm just trying to find a more flexible solution, in case they come up with some new BS type I need to check

unborn sphinx
paper mirage
#

One question, do you only ever need to check two games GameAsset files against each other?

unborn sphinx
#

which all could be avoided if we played them consecutively

#

nobody can play simon says and sudoku at the same time

#

it's all ....

#

BS

#

or chess and crosswords.

#

you get the idea...

paper mirage
#

so you're looking to find which 50 games share the same value for a certain property, right?

unborn sphinx
leaden ice
#

Hoenstly sounds more like a "tagging" system would work better

leaden ice
#

give them a Dictionary<Tag, int> or just a HashSet<Tag> then it becomes pretty trivial to check the existence or value of particular tags

unborn sphinx
#

best part is
they told me yesterday "well, we may end up killing the idea, but you first finish it"

leaden ice
#

instead of having individual fields

hexed gale
#

guys for some reason my player cant jump, this is my code
if (Input.GetButtonDown("Jump") && isGrounded())
{
rb.velocity = new Vector2(rb.velocity.x, jumpPower);
}

    if (Input.GetButtonUp("Jump") && rb.velocity.y > 0)
    {

        rb.velocity = new Vector2(rb.velocity.x, rb.velocity.y * 0.5f);
    }
warm stratus
#

Hey, i use a Rigidbody Player and a fps camera, but i use item picker, but when i hold an item, the item goes every frame to the placement of the tool which is a child of the camera, but the movement of the item is jittery, how do i fix it?

leaden ice
unborn sphinx
#

I just went with enums fo the others to be able to set the respective values of THEIR games in the inspector

leaden ice
warm stratus
leaden ice
#

when

warm stratus
leaden ice
#

where

#

when

#

how

#

Show code

#

explain the components on everything

#

details matter ๐Ÿ˜‰

warm stratus
#
public void SmoothTool()
    {
        if (toolInHand == null)
        {
            return;
        }

        toolInHand.transform.position = toolPlacement.position;
        toolInHand.transform.rotation = toolPlacement.rotation;
    }

it s what i showed yesterday

leaden ice
#

Yeah I don't remember what I ate for breakfast so

leaden ice
#

where and when is this code running?

#

Where and how is toolPlacement moving

#

etc

paper mirage
warm stratus
#
private void CameraMovement()
    {
        //rotation of the entire body
        playerOrientation.Rotate(new Vector3(0, mouseMovement.x, 0) * mouseSensibility);
        
        //rotation camera up and down
        transform.Rotate(new Vector3(-mouseMovement.y,0,0)
                       * mouseSensibility);
        xRotation -= mouseMovement.y * mouseSensibility;
        //rotation clamped to these values
        xRotation = Mathf.Clamp(xRotation, -90f, 90f);
        transform.localRotation=Quaternion.Euler(xRotation,playerOrientation.eulerAngles.y,0f);
        
        toolManager.SmoothTool();
    }

here in the camera Movement script

#

and the tool object is a child of the camera @leaden ice

fervent furnace
#

for any camera movement, the only suggestion i can give is move camera in lateupdate()....

unborn sphinx
unborn sphinx
#

again. If it wasn't for the unplayable hellscape idea of playing two minigames at once (per player mind you!), this wouldn't be necessary

#

heck, at some point one guy even suggested, "theoretically, one can play even 3 games at once. In shooter games I have to shoot, keep track of my ui and enemies, that's the same thing" (although "keeping track of things" is just a peripheral action not involving actual "interaction", so it's NOT the same)

warm stratus
paper mirage
#

Hmm, seems like a very messy project, yeah. I wish you good luck in not choking on all the spaghetti!

unborn sphinx
#

thx for everything.
I'll try some of the suggestions later.
Venting also kinda helped...

mystic ferry
#

if you store the result of a 2D raycast in a var, the type is RaycastHit2D which makes perfect sense, but what is happening under the hood when you change var to bool? suddenly the function returns a bool instead. How does that work under the hood?

hexed gale
#

what to do?

somber nacelle
leaden ice
#

investigate why it's not determining itself to be grounded

autumn gorge
#

So I followed the vr inverse kinematics videos both upper and lower from Justin p Barnett but I can't get them to work I have attached some code and a video to see what is the problem any help is appreciated https://pastebin.com/JJuXMj9C https://pastebin.com/KQugHigw https://pastebin.com/4rmY3w9C video: #๐Ÿ’ปโ”ƒcode-beginner message

autumn gorge
paper mirage
knotty sun
earnest gazelle
#

Is there any way to build polygon meshes for sprites manually in unity or change the default one?

leaden ice
cunning meteor
zinc parrot
#

Is there a way to have a progress bar without using a serialized object to get the data?
serialized object makes unity lag cuz the object itself contains a huge amount of data

leaden ice
#

what does "using a serialized object to get the data" even mean?

#

That feels extremely specific to whatever you're working on

#

you can get the data from wherever you want/need to

#

ยฏ_(ใƒ„)_/ยฏ

#

All you need is a number 0-1

zinc parrot
#

so, the previous method I used used the uielements progress bar, which requires binding a serialized object to read the data

#

but that lags the editor to HELL because the object that gets serialized is a script that contains possibly gigs of data in arrays

leaden ice
#

you can bind it to any property you want afaik

zinc parrot
#

but I need the data from the heavy object

#

cuz it runs in an async task

leaden ice
#

you need some interpretation of that data

#

you don't need all of the data itself

leaden ice
#

make a property that reads that

#

and bind your progress bar to the property

zinc parrot
#

oh? ok ill try!

marble laurel
#

is there any people using photon fusion ? i've a problem how to run function StartGame when i load scene from addressables

primal wind
#

So lets say i have a BaseTile class and a TrapTile class that inherits from BaseTile, does GetComponent<BaseTile>() also work on TrapTile?

latent latch
#

It works like general c# inheritance. It will find the component, but have the functionality of the base class unless you've got overidden methods.

primal wind
#

Okay cool

latent latch
#

So you'd have to cast it later if there's methods not implemented in the base which you need.

ancient cloak
#

good use case for interfaces, since any reference stored as an interface type will only be able to use the interface-specified methods

upbeat hare
#

anyone knows how to add an audio in the script like footsteps, jumping and selecting weapons?

upbeat hare
potent sleet
tawny elkBOT
upbeat hare
#

oh

#

thanks

earnest gazelle
#

Probably, I have to use external libs like texture packer

leaden ice
#

but it's a little unclear to me what the goal is here

#

if it's not about physics why do you care terribly much what the mesh shape is?

#

If you mean you want to slice the sprite out of the texture differently that can also be done from the sprite editor I believe (at list if can be when you are using sprite sheet, not sure about single sprites)

earnest gazelle
#

I use a cutout shader

#

they are plants and grasses. Also, I want to shake them when there is wind
So, I would like to build a custom mesh for each precisely

regal violet
#

Hello guys, is it possible to overlap shader to draw one over the second ?

I would like to have only the red square.

knotty sun
#

do not cross post

hollow loom
#

Sorry

ashen yoke
#

afaik you can have opaque tag but still render it in non opaque queue

#

maybe its that

#

is that an issue similar to transparent sorting failing on single mesh geometry?

rugged storm
#

i have this script

public class LaunchGroup : UnityEngine.Object
{
    public Dictionary<Vector2Int, Packet> Packets = new Dictionary<Vector2Int, Packet>();
    public MatchedGroup MatchedGroup;
    public PacketGrid PacketGrid;

    public LaunchGroup(PacketGrid packetGrid, MatchedGroup matchedGroup, List<Packet> packets)
    {
        this.PacketGrid = packetGrid;
        this.MatchedGroup = matchedGroup;
        foreach (Packet packet in packets)
        {
            Vector2Int relPos = Vector2Int.RoundToInt((packet.transform.position - matchedGroup.packs.First().transform.position));
            this.Packets.Add(relPos, packet);
            packet.launchGroup = this;
        }
    }
}

why is this null in packet.launchGroup = this;

ashen yoke
#

: UnityEngine.Object ?

simple egret
#

this can never be null

ancient cloak
#

well, it can but only in like an event you fail to unregister

rugged storm
#

im using UnityEngine.Object so that, a refrence in another object to a LaunchGroup can be null

simple egret
#

As long as it's a class it can be null

#

No need to inherit from a particular class

rugged storm
#

oh i mean imim using UnityEngine.Object so that, a refrence in another object to a LaunchGroup can be null while LaunchGroup is [Serializable]

simple egret
#

Mhm, no need to inherit from UnityEngine.Object

#

As long as it's marked as [Serializable] Unity will interpret it correctly

ashen yoke
#

if you need weak reference use weak reference, im pretty sure such hacks will result in undefined behavior

simple egret
#

Also I don't think stuff deriving from UnityEngine.Object, plus that are serializable, likes parameterized constructors

rugged storm
#

oh wait actually i could just have the object set it's reference to a LaunchGroup to null so that the inspector does not make it not null

ancient cloak
#

what even are you trying to accomplish

#

this reeks of XY problem

rugged storm
#

my B ill explain it from the bottom

ancient cloak
#

don't even explain it. just what are you trying to do

#

end result

rugged storm
#

Basically I need to LaunchGroup to start as null on another object I have to do this I tried changing it to UnityEngine.Object and now "this" is null during that statment

ancient cloak
#

can you go higher level

#

i still have no idea what you're trying to do

ashen yoke
#

its designed to point to a native object, implicit casts are designed for native object, directly inheriting it is a minefield

rugged storm
#

i need public LaunchGroup launchGroup; to be null on a Packet untill i make a new LaunchGroup where it is a part of List<Packet> packets in the LaunchGroup constructor

ancient cloak
#

why

ashen yoke
#

use weak reference

ancient cloak
ashen yoke
#

or use events to notify packets when launch group is created

#

or use lazy init

rugged storm
#

whats a weak reference and whats lazy init?

rugged storm
ancient cloak
#

hey my dude. using human, non-syntax words, can you explain to me l ike a human, what you're trying to accomplish

#

now that solution you're trying to use

simple egret
#

From what I understand?

LaunchGroup lg = new(..., packets);
packets[n].launchGroup = lg;
ashen yoke
#
class MyRef<T>
{
    public T value { get; private set; }
    public void SetValue(T val) => value = val;
}

class Packet 
{
    public MyRef<LaunchGroup> launchGroup;
    public Packet(MyRef<LaunchGroup> lg) => launchGroup = lg;
}

// somewhere else later
foreach(MyRef<LaunchGroup> lg in launchGroups)
{
  lg.SetValue(newLaunchGroup);
}

example

rugged storm
#

Basically im trying to make a metos clone and im trying to make each block (Packet) remember the group it was last a part of, i have code that i only want to run if it is a part of a group, so when they first spawn i want the group its a part of the be null so i can check if packet.launchgroup == null

ashen yoke
#

its pretty much what UnityObject is, but designed for c# objects not native unity ones

ancient cloak
#
public LaunchGroup? launchGroup;
ashen yoke
#

thats the same as just launchGroup reference?

rugged storm
#

I also want it to be visible in the editor, but making it Serializable makes it start as not null

ashen yoke
#
class MyRef<T>
{
    public T value { get; private set; }
    public void SetValue(T val) => value = val;
}
[Serializable]
class LaunchGroupRef : MyRef<LaunchGroup> {}
#

tho this should be marked with NonSerialized or somehow else disable unity serialization on it

#

with odin i can just ShowInInspector

ancient cloak
#

i'm curious why you want a constructable object assigned via inspector

rugged storm
#

tbh I just want to see it easily without a having to put breakpoints and find the specific block I want to look at

ancient cloak
#

what blocks

rugged storm
#

I just wanted to be able to click it in the Scene view and see what group that particular Packet is a part of (if i say Block i mean packet)

ancient cloak
#

idk what packets are. network packets?

#

you could add a gizmo that displays the group number/name

rugged storm
#

meteos is a falling block game, its basically a match 3 the packets being actual blocks as my game is themed around coding

ancient cloak
#

okay

#

so the X in the XY that i've been asking for this entire time

#

is literally clicking on something and seeing visually what group it's part of

rugged storm
#

Yeah

#

sorry i can be dense at properly explaining stuff at times

ancient cloak
#

OnDrawGizmosSelected, you can draw a wire mesh or sphere around every object in the group, you could display the group name

#

you don't need a special BS hacky solution. you can leverage whats at your disposal

rugged storm
#

Oh, tbh, I forgot OnDrawGizmosSelected was a thing and i only even knew about how to draw a square with it so ill look into the stuff I can do with that

#

ty

ancient cloak
#

so is it like, a "group" are blocks that get connected for potential removal?

rugged storm
#

In meteos you match blocks to launch them up into the air so the "launchGroup" is basically a way for a block to remember what blocks around it should also get launched if it is being launched

ancient cloak
#

oh ok

#

so it's just a group of blocks. cooleo

rugged storm
#

yeah a group of block and the blocked that were matched to launch them (matchedGroup) and the overall grid they are a part of (packetGrid)

ancient cloak
#

yeah what i'd do is i'd make a mesh that's like ever so slightly scaled up from the actual mesh. same scale might work, i'm not sure. but you can just iterate through the group in OnDrawGizmosSelected and Gizmos.DrawWireMesh(myMesh, block.transform.position, block.transform.rotation, block.transform.scale/maybe scaled up/);

#

then when you click on a block in the inspector, the group should light up with wireframes

rugged storm
#

actually I have 0 clue how to make a combined mesh out of a bunch of squares

ancient cloak
#

you don't

rugged storm
#

Oh wait nm i get what your saying

ancient cloak
#

you iterate over and call Gizmos.DrawWireMesh on each block

rugged storm
#

yeah I realized you meant a foreach loop for launchGroup.packets

simple egret
#

Note that Gizmos are only visible within the Editor. If you need to highlight them as a part of gameplay, you need to use something that will work in a standalone build, like a Line Renderer

rugged storm
#

๐Ÿ‘Œ

rugged storm
ancient cloak
#

you can serialize a mesh reference and assign it. you can get an object's MeshFilter component and access MeshFilter.mesh

rugged storm
#

okay how would I just make a 1x1 square mesh to pass in as the blocks will never have a different mesh

ancient cloak
#

[SerializeField] private Mesh _mesh;

#

then you can just assign the mesh that the cubes use

simple egret
#

In that case, you could use the simpler Gizmos.DrawCube method

rugged storm
#

true good to know how to get the mesh of an object tho

#

also id have to be public because id be passing in block.mesh in a theoretical case where a block in in the group has a different mesh from what the block i selected has right?

simple egret
#

Do your objects even have meshes? If they're purely 2D objects, they probably don't

rugged storm
#

IDK? i guess no? i specified 2d Square game objects hoping you guys would know

simple egret
#

You need to look at the object's components to know

ancient cloak
#

doesn't matter if you're just drawing a cube with gizmos

simple egret
#

A Sprite Renderer does not render a mesh. Actually anything that doesn't have a Mesh Filter doesn't have a mesh

rugged storm
#

Ah. Okay so I'll just go with drawing the cube then

elfin vortex
#

How can I flip the X axis of the sprite renderer after I play an animation? I know I can use "spriteRenderer.flipX = !spriteRenderer.flipX;" but I don't know how to flip after after the animation ends. I tried doing it on the animation itself but it only flips on one frame and goes back to normal when the other animations play. I'm not using the animator tab directly, I'm doing it all through an animationController script.

simple egret
#

If it resets, that mean the next animation that plays has the flipX property keyframed. You could also use an Animation Event to call a C# method that modifies flipX for you

elfin vortex
#

Oh yeah, I'll give it a try

#

it worked but I think I need a different solution. For context: I have 2 animations, moving and turning, when the turning animation ends it should flip the X but only when moving begins, otherwise it flickers by flipping at the last frame of the turning animation.

near rover
#
        {
            foreach (var rb in go.GetComponentsInChildren<Rigidbody>()) rb.isKinematic = isKinematic;
        }``` 

This is clearly not the correct code but I'm dumb.

How would I set all rigidbodies in self +children to kinematic?
#

I thought this would work but I was wrong ๐Ÿ˜ญ

simple egret
near rover
#

ah I fucked up the syntax

#

ok thank you!

twin hull
#

what was wrong in the end? seems fine to me except no void @near rover

near rover
#

turns out I was right

#

No worries, thanks!

tall lagoon
#

hey guys sorry to intrupt but im making a wave spawener game for a game jam and imexpanding ona tutorial i saw on a wave spawner system and im moving the elements from 1 list to another and the other list is list of eneimes that the player has to kill.Soi was wondering how can i remove the enimies from the kill list when they di or when theyre health his 0.bc right now i made a for loop but i dont think it works

lean sail
#

What doesnt work

#

I assume its because you're removing the .gameObject

hidden parrot
#

i cannot read that shit
can you paste this instead of a screenshot

#

thats in the read me

worldly hull
#

i cant figure out why this problem appear so i just gonna describe what i did

#

im asked to modify one of the script from a package

#

to make it easier , i move that particular script into another file together with other prefabs

#

by the moment i did that it seems that everything is falling off, all other script cannot reference this script

lean sail
#

does the script use Resources?

hidden parrot
#

I

worldly hull
#

no

hidden parrot
#

I'm thinking it's to do with assembly definitions?

worldly hull
#

it does have something like namespace

#

but i think it doesnt matter?

prime sinew
#

are there errors

worldly hull
#

The type or namespace name 'TestCustomizerDD' could not be found (are you missing a using directive or an assembly reference?)

hidden parrot
#

Does the package you installed use a separate assembly definition to your own?

#

Look in the package files for an assembly definition
One sec, looking for the icon

spare island
#

can constructors not work from monobehaviors or something

hidden parrot
#

This icon I believe

spare island
#

Was there some kind of change

lean sail
hidden parrot
#

You shouldn't be using a constructor to create a monobehaviour

#

addcomponent

spare island
#

I don't remember why I did it

#

unfortunately debugging code from over a year ago

lean sail
spare island
#

I must have some reason I did it

lean sail
#

or i guess add component can be used nvm

hidden parrot
lean sail
#

i was thinking of spawning an object

hidden parrot
spare island
#

but it used to work which is weird