#archived-code-general
1 messages ยท Page 112 of 1
Something like this
i dont see the code where it doesnt work
im a noob bro
i know
I don't understand how to set it up
do something, show the code of that something
bruh what
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"
StartCoroutine(waiterAddLine());
IEnumerator waiterAddLine()
{
mCanAddLine = false;
yield return new WaitForSeconds(Utils.ADD_LINE_UPDATE_TIME);
mCanAddLine = true;
}```
Something like this should do the job
alright
please do not spoonfeed, it does not help in the long run
what makes you lost?
https://docs.unity3d.com/Manual/Coroutines.html
The manual should take you from A to Z.
I don't know where to put what
you see the yield return ?
yeah
you need to modify the UVs before they're used to calculate colors
oops, I was scrolled way back
solved :p
so a coroutine will suspend its execution on each yield
then it will continue from that exact place
so where do you put it?
Happens to me a lot. Especially on mobile with the digital keyboard taking nearly half the screen.
I just forgot to scroll down :p
what
the code you want to execute
under the yield?
right
okay
can you picture what is happening?
yeah
๐
So wait hold on
like this?
well i have one more thing
I need it to only work ontriggerstay
okay done
look at the code above, and try to understand what is happening
you launch a coroutine once, it waits for 5 seconds
think about it, what do you want to do after the wait?
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.
before everything else config your ide
this whole method you wrote should be red from errors
okay done
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
yes
well thats good
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
or GetKeyDown, or StopCoroutine before starting a new one or some bool, there are lots of options
can i use GetKeyDown with OnTriggerStay?
simplest is a guard bool
GetKeyDown will return true only on the frame the button was pressed
you have to "guard" some block of code from executing twice
okay
for that you use a bool to store if it was called already
and before running that block you check the bool
declare a bool
name it for the purpose of it
I did?
wasDoorSlammed
okay done
so if statement?
yes
this will still launch coroutine itself
move the check to the coroutine start instead so you only ever start 1 coroutine
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
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?
Did you actually test it on your device?
anyone know how to fix VS when right mouse options are missing? like find references etc
moved computer and its caused so many issues
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
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
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
show the declaration for EventManager.OnMinionDeathEvent
OnMinionDeathEvent is not the same as MinionDeathEvent
You need a MinionDeathAction whatever that is
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
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
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.
there is a purchase log that increases with every Shop bought and keep track of how many is bought
You could simply run the same logic, that you use when buying an upgrade, on start based on the loaded data.
Ok thank you ill give it a go
Hello guys! I am having an issue with using my brain for math. Basically I want to be able to put an object's position behind the player. The player doesnt move, it only rotates. Here's what I have right now: https://gyazo.com/0d9b8e86b0903b6518f75ba78b3401e9
Ultimately I want to have a trail of crabs that follow behind the player
I just cant math rn
theCrab.transform.TransformPosition(Vector3.back * distance);
It's telling me TransformPosition is not a transform function
"'Transform' does not contain a definition for TransformPosition"
TransformPoint my bad
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
Yea 2D game. Think about it as if it were snake
I'll try
I think I have to use CrabTransform.down / left
right?
Instead of Vector3.down
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
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:
so CrabsPositionList[i].transform.TransformPoint(Vector3.left * offset)
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
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:
can you show the hierarchy? And what are the z positions of everything?
and what is the camera angle
sure 1 sec:
also is the yellow guy on the left the player?
or... the red crab in the middle perhaps?
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
this looks like it's working for the green crab in particular
at least the position
Yea the position seems ok but they act weirdly
the goal is to have something like snake without the grid constraints
ok so
it looks like the spawned crabs are also children of the main crab?
They are not
wait also it looks to be working properly in this video now?
?
Right above it is the PlayerCrabHead
which is the player
Crab body is an empty @ 0,0,0
what is CrabBody?
it holds all the crabs that are pooled
wait I'm also seeing that... all of this seems to be happening inside of a canvas???
Yea it's a 2D game
2d games should not be made on a canvas
canvases are for UI
2D games should be made using SpriteRenderers
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
the behavior shown here looks mostly like the behavior you asked for. If you want it to "lag" behind, you'll need to interpolate them to the desired position/rotation rather than doing it instantly
it's unclear to me what the desired crab rotation is though
it should be the same as the player
This is the desired behaviour
but that is a completely different thing
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"
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)
Looks like visual scripting? ๐ค
There's a Bolt server, maybe you can ask them there #763499475641172029
Yea it's tricky because the last position of the player is always the same
It's not visual scripting, its a Behavior Tree
visual scripting controls the how, behavior trees are just flow control and there's not really a relevant channel to that
They've got a dedicated server link listed in the asset store: https://assetstore.unity.com/packages/tools/visual-scripting/nodecanvas-14914
anyone know why my scriptable object doesnt show up in the create menu?
[CreateAssetMenu(fileName = "New Spell", menuName = "Spells")]
public class spellScriptableObject : ScriptableObject
{
Do you have any compile errors?
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?
what do you mean by "actual shape"?
It's a cube and I just used other shapes to make it look like a trapezoid using colliders
yep that fixed it thx
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?
what's harder than serializing dictionary is you trying to save a gameobject in a json
reference types should prob be the last thing you'd wanna try serialize
So I should create a lookup system
does it matter btw if player changes those values ?
how can u serialize dictionaries? im actually tryna do that rn
@leaden ice I got it somewhat working! I just need a bit of lerp on the rotation I think to make it "lag behind" https://gyazo.com/55cdbe08d2cef89e766f16e59a228503
thanks let me check it out, ik there a few plugins but they are quite expensive
also use Newtonsoft instead of JSON utility
If you're referring to the inspector, you can't. There are a lot of gimmicks out there with serializing arrays of structs and whatnot to later fill a dictionary (during runtime if need be) - plenty of free assets or paid assets like Odin as well.
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.
you can with the callback
Custom editor?
nope, just as is, maybe with a wrapper
and if they can just restart the game to try again if they go over what they think they can fight this system doesnt work
Ohh I see.. You could potentially store that remotely as well if want to make sure it's never touched
read the json from web
using UnityWebRequest
here he uses a custom class to wrap it
but you dont need to
you can serialize in place in the mono
yea thats what i was doing, using two lists and putting them back into the dict but thats p inefficient
How would I host files on the web? Is it as complicated as I'm imagining it? lmao
Not that hard but you do need either a webhost and make some sort of custom POST
or you can use something like a database
FireStore/Firebase
Lootlocker
mongodb
etc
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?
Looks like the bare minimum of what's illustrated from the docs: https://docs.unity3d.com/ScriptReference/ISerializationCallbackReceiver.html
if it's stored locally anyone can modify it
it's not super complex. You basically just serialize a list of your key/value pairs
Yeah, but with encryption you'd have to know the encryption key, no?
unless they don't know it's a json file you can obfuscate it storing as byte
or som
you're confusing two different things
nothing is encrypted
you just store and retrieve data/json remotely
with API calls
no one can touch your file remotely
Nono I'm saying my save system has encryption already so there shouldn't be an issue with saving locally
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
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
learn to store to a local DB first and then do the same thing remotely
Is this a multiplayer game?
nope
Player storage allows you to store key/value data on the player. Storage items can be private or public, making possible
what are we storing remotely then and why?
wait wouldn't storing data remotely mean that you'd need internet to play the game lol
yes
list of chosen enemies so the player can't modify it and break the core mechanic
you can still store it locally but yes you'd need a connection to eventually send/retrieve the DB
If a player wants to go through a ton of effort just to cheat at solitaire - do you really care?
fr
yeah I was just thinking about that
who are they really cheating, besides themselves, in that case?
just don't put online leaderboards :p
true enough. If I go through the effort for that I can just learn remote data storage then.
literally storing sum like .dat or .bin
throws of most regular players anyway, they wouldn't know to mod that
although I doubt this game is even going to be published honestly
there's lots of videos for this on youtube
!learn
๐งโ๐ซ 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/
if you want advice you have to ask a question related to something..
sorry my bad
you're saying hide the save data as one of those file types?
you can save it as whatever extension you want
if you really cared to, you could encrypt the data. Though your encryption key would likely be in the files meaning it wont stop people who know what they're doing. It would also be susceptible to certain attacks but at least its a better deterrent if someone were to find which file it was
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
Yeah, I have implemented that already just to make sure that it isn't too easy to cheat. If they're gonna cheat, they'll at least have to put in effort.
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
that's a lot of effort for a solitaire type game
id say just keep it at encryption, leave it be, and save your mental by moving on
yes, or as its called: encryption
yeah but again, it's a singleplayer game. Once they get to that point they can do whatever they want if they're willing to go through the effort of finding the key.
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
it's not a solitaire type game, just a survival shooter with a... different approach to enemy spawning
sorry you said poker
lol wrong card game
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
I was saying the idea is based on the idea of blackjack, that's all
gotcha
risking it without going too far that you end up getting yourself killed essentially
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.
but that's harder than and less reliable than XOR encryption so there's really no point
why opt for a worse method though
how is XOR worse than binary encryption?
I dont know why unity says theres no closing bracket when there is. Pls help
harder to implement manually from what I know
configure your !IDE
and you can't declare public members inside a method ๐
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.
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.
access modifier doesn't go in a method
and configure your IDE
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
if a game is singleplayer/offline then forget the protection, its better to be open
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
could you use cloudsave to store your aes keys
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
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
this is some weird logic in saying that u personally dont want to encrypt. Others dont have the same goal in mind as u
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?
A huge chunk of gamers seek games specifically that they can mod, you are losing players by taking obsessive measures to prevent someone from just having fun.
This isnt even related lol, you can still have mods in your game but prevent your user from acquiring every single item by just changing plaintext
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
Mods arent the same as just editing a save file, at all
Its a local game, whats the harm in someone editing a save?
Okay, so I guess a good idea would be to be sneaky with the key
hide it in the sound manager or something
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.
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
and thats simply your opinion on it. I dont think you understand how modding works, so i really dont care to argue further about it. You can still allow mods and encrypt the data
that really wont change anything
in this case, offline game tho, no data really needed to hide
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.
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
Every single game that ive edited save files for, ive lost interest in the same week
I kinda like it. Just feels a little more professional to just put the extra effort?
encryption really isnt even effort to implement, its like 3 lines of code lol
Properly building as IL2CPP is more pro
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
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
what do you mod on a solitaire game
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
Ah, I saw him mention solitaire sorry
Exactly, nothing XD, you dont mod mobile card games - its odd for someone to go through extensive measures to try and encrypt stuff for not much reason
"extensive measures"
Exaggerated. But just the fact of trying all sorts of things to protect all corners
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
thats when you do it. not now
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.
i really have no clue what your point is. If you personally dont wanna encrypt then dont lol
That's why it's important to provide proper context to your questions.๐
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?
I did, but it got misinterpreted after
Perhaps
first configure your IDE
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.
also you're trying to assign a sprite to an image component
remove Image image =
or set Image componet first then do image.sprite = myspriteorwhatever
if you remove it later then peoples saved data will be encrypted and the game cant read it. Release the game when its complete, learn about what people like/dont like/what they hack, then youll know the right areas to protect and what to change. If you put your best effort into encryption on day 1 and people get in.. then you dont have much left to update with.
Oh, I'm just doing simple XOR encryption. next to no effort. I'm not saying I plan to remove it after the game is released either. And again, it's singleplayer, I'm not worried about encryption being strong as long as anyone can't just open the file and change things just like that.
same with if you dont encrypt but suddenly need to...
so the best action would just be encrypt it first incase you add features.
Release the game when its complete
never heard of games having updates?
Sounds good. Makes sense if its the core mechanic
Yeah. And like I said, to the average player it doesn't make the game any more or less fun in any way regardless of who you are.
This isn't going to stop people from cheating.
Just went over that it doesnt matter if they cheat, its SP
what's the issue with people modifying singleplayer state data?
No, but it will make it so every player doesn't cheat whenever they feel like it. Like I said, singleplayer, I don't care if they can cheat, I just want it to be a bit harder than simply swapping some numbers in a file
If you want it to be harder, then binary serialize it
encrypting this is the worst way to go about it
why wont debug.log or console.writeline work?
Why? The average player isn't going to decompile the game to find the encryption key.
use Debug.Log("test"); - for console youll need to add system imports
anyone who does, whatever. Go ahead at that point.
Your mindset makes no sense
configure your IDE
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
What does it matter if someone cheats on a singleplayer game though? Everyone does that
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
I said I don't care as long as it takes some effort so that most people don't do it. And it just breaks the game loop anyways if they edit this file in particular, making it so there really isn't a game anymore
Your thoughts are not in the right place pal
@lean sail I did
from this screenshot, u did not. If you did though, reload your VS so you can see syntax highlighting
You are being rude to him. Its been made that it doesnt matter if its cheated. It makes sense to want to have at least some protection rather than being a purely open game looking like a noob build
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
I thought all I had to do was change the external script editor to vissual studio?
No. !ide
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.
XOR is like 6 lines of code, it's not that deep
It's not like I'm putting a week into this
when you're not using binary formatter it is
yeah binary formatter is a no-go
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?
No need XOR, build as il2cpp, save file as dlc.bin
device. I build in unity for the apk file then put it on google drive, on mobile device I download the app
It says I have to modifie visual studios in package manager to update the IDE but its not in there
thats like the last step dude
there are more important ones to do before it
also it would be under InProject not MyAssets
the only other step it says to do before that is this which I already did
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? ๐ค
what about the Unity workload package
how do i add that?
but this page doesn't even have versions for 2021.3 or 2022.2 (which I am using) so I assumed it doesn't work
It's highly unlikely that unity would allow things to break between updates
especially the API
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
{
public string name;
public string version;
}``` This aren't keyvalue pairs
If your structs are in a dictionary, then it's no different
it doesn't really matter here. how do I generate json?
I just linked you to a whole page dedicated to json in unity
it does matter, you wont get the same pattern
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.
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
w a t
are u making a game where the user builds their own game?
hey cnfnbcn
who said I am making a game in the first place?
I outlined what I want pretty clearly
no, you haven't
maybe instead of using jsonutility try using newtonsoft json? It easily writes to json with proper indentation
reads objects too
I don't want any dependencies for this package
I don't think that's going to make much of a difference
the indentation isnt the problem, they just dont have the data in the right format to begin with
yes. question is how do I make it right format ๐
I am about to just manually write whole file instead of jsonutility. but I thought maybe there's non-roundabout way of doing this
I think Newtonsoft package can serialize a dictionary as a json object(what "dependencies" end up being in Json).
wait can't jsonutility serialize dictionary? let me try
the problem is that I don't want any dependencies (by design)
Then write a custom serializer ๐
that's what I'm about to do yeah
@granite nimbusIf you're going to write your own serializer, do yourself a favor and skip text based parsing and just do binary serialization.
They probably need it like that for unity to recognize it as a package manifest or something
Binary isn't gonna work
yes, I just need package.json
I'll just do non-universal proprietary serializator for package.json only and it will do
I wonder if there's an editor utility method that creates it though. Unity somehow creates it, does it not?
I doubt it does? it just downloads existing ones
they already exist in packages
Ok, and how is the downloaded file created?
no idea ๐
I doubt they create it by hand every time...
Maybe they have some external tools for that they don't release.
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.
I've had the same issues with things relating to animation. Lots of useful stuff only available in the editor.
Ah, good news. I can detect the tangent mode manuallly.
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;
}
@potent sleet Thank you so much for you help it finnally works
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
what that hek hah
!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.
trigger events still work even if the object is disabled
Link large codeblocks using external services, as was mentioned in the bot message.
why u dont use !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.
what do u mean you tried disabling trigger?
Cartrig.GetComponent<BoxCollider>().enabled= false;
Cartrig.GetComponent<BoxCollider>().Istrigger= false;
mk my bad
delete that haha
can you show the hierarchy, and whats actually happening because theres a lot of components in that script you sent
yeah sure
https://hatebin.com/mwzewtgbrt Car Prox script
https://hatebin.com/cltvdmviel Car Enable Script
the game objects
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
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
CarProx is where most of the trigger events are* happening
Car Enable is the script where it is supposed to disable everything
which object in this hierarchy actually has all of these components being used in CarEnable
Car
you need to explain the issue a bit better, where does CarTrig even come into play?
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
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
CarProx is in Car
if CarProx is in Car, then how is CarTrig "used" for the CarProx script
because CarProx would be referring to any triggers on the Car
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
I only have the CarTrig with a trigger enabled
yes but you said the CarProx script was on the Car
yes
so its not on CarTrig..
whats CarTrig even for then
to detect if the player is by the car
if CarProx is on the Car and not on CarTrig, CarTrig wont do anything
what components do u have on CarTrig
just box collider
yes so its not going to do anything then, its just a trigger with nothing on it
what doesnt disable
Does anything else get enabled/disabled when you press E then?
and is Car Enable active when u do this
The Car Controller script gets enabled as well and player object gets disabled so it doesnt collide with anything
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;
}
}
add debugs in your scripts to log whats actually colliding. I really dont know what you're describing because i dont know your game, also I dont get what the actual issue is vs whats supposed to happen.
https://docs.unity3d.com/ScriptReference/Collider.OnTriggerExit.html
Trigger events will be sent to disabled MonoBehaviours, to allow enabling Behaviours in response to collisions
don't switches need a case default: in cs?
I have one further down anyways, this is only part of the switch.
If there's nothing wrong with this section then my problem lies elsewhere, but I seriously doubt that.
post the full context because its harder to suggest things when its solved somewhere else
Thanks for helping anyways Im about to go to bed here Ill probably try to fix this problem later tommorow I appreciate you trying to help
huh?
No, it's not necessary. If I remember correctly...๐ค
compiler doesn't complain, I've done it before without default. Probably best practice but not required.
dont hide parts of the code, there seems to be a bit of missing context in here
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)
{ ... }
yea so some parts are missing.. do you know if the switch statement is whats causing it to hang for sure
I don't see anything particular in this code that could cause a freeze. But it could be calling something that does cause it. Use the debugger during the freeze to figure it out.
what parts are missing???
If nodeObject has this script on it then it'll freeze
it doesn't... I don't think. I'm reloading unity now.
Use a debugger and save all of us some time.
i forgor VS debugger
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.
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?
It's more of a geometry issue making something like that, although if you're okay with triangles you'll get a pretty nice distribution with subdividing an icosahedron.
how big is the sphere compared to the grid?
you could look at a Mercator projection, but I think the triangle option as suggested above would be a better solution
Wdym?
Ok ty
Do you mind if you DM me and explain it to me
Consider it done ๐
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
I believe Rigidbody.MovePosition can help you, though it might do the same thing?
Otherwise a Rigidbody.Sweeptest could work
I have not tried that, but I'll give that a test later
but thanks for the help ๐
Generally, if you rely on proper collisions, you should move your object via physics as well.
Im a begginer can someone help with a small code
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)
Help with what?๐ค
client takes position delayed
Okay?
Thats a problem i guess?
Did you expect a multiplayer game without latency?
but is on localhost
No. That's totally normal.
Regardless. Depending on the implementation, there's still overhead.
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.
is normaly. because server tickrate, send data between player
Thanks, this delay scared me a lot, to solve this, I will process the position through the client.
other than that, I still do things with the server
Healt raycast etc.
That's the point where you start learning about latency compensation techniques.
Just moving your character on the client is sure way to lose sync between client and server.
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 (:
you dont, thats the fun part
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
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.
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?
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.
It's weird cuz the method under is using the exact same switch but it doesn't get the null error
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?
yes it is
addItem gets called from another script whenever is press E
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
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
ahh I see now
huh it works tho
Calling it from another script would still show a reference
your saying UseItem never gets called
VS is saying it isn't
lmao
apparently not
then how does it work
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?
I can't find it
I'm so confused rn
the debug shows
Show a screenshot of the debug
It's coming from line 69 on InventoryItemController
This is on line 88, in an unknown (to us) class
its cuz I removed the switches
its on 69
gimme the money
Ahhh
@trim schooner I know
why
the method
is being called
with a UI button
is it an rule XD
Yes.
#๐โcode-of-conduct โข Not using complete sentences.
#854851968446365696 โข Use full paragraphs with the information ready.
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?
A serialized array is by far the simplest and most efficient option.
You could write some custom inspector if you want to represent them in a different way graphically or something
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.
^
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?
can you call a switch statement for grabbing player input like w/a/s/d
There are even builtin parsing methods for such tasks, right?
The "I've considered doing it that way" part was a reply to the custom editor thing
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)
I mean you sort of can, but it's slower and why
ยฏ_(ใ)_/ยฏ
figured it looks better and easier to read than a bunch of if statements
Not really, because I'm not thinking of just splitting by comma and then parsing ints, I'd want to add logic for realtime format validation to remove the possibility for user error. I'm generally not a big fan of letting users type in invalid values in inspector fields.
why not this:
Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
rb.AddForce(input);```
if I wanted it to be snappier I would use .velocity instead of .addforce right? .addforce could make the player accelerate faster and faster?
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
why would you then want to expose the array to the inspector in the first place, if nobody should touch it (out of fear of wrong values) and you hate interacting with UI?
or larger forces ๐คทโโ๏ธ
The important thing is you understand the difference between adding forces and setting velocity directly
you'd have to show your code, and potentially add some logs to figure out what's going on
People will touch it, and I don't hate interacting with UI? I'm not sure where you got that impression. I just want UI that's foolproof, to reduce the amount of user error
last part of the last sentence
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
hmm, yeah I can see the downsides to using both
Talk about instakill
guess I'll have to test and see thanks...its going to be a 2d dungeon crawler style
That's me complaining about unity's UI for serialized arrays, not me saying I hate interacting with UI. It's specifically about that UI, not about all UI
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.
Hey, how should I recalculate normals, to have them flat and not smoothed like this? The mesh is generated procedurally
I have no idea if this would work, but this could be a potential solution
what kind of code are you hoping this to enable you to write?
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)```
[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
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);
}
}
can someone explain it please?
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
I'm not sure I understand tbh
what do you mean by "comparing with the next game"?
it's a game package
yeah but what kind of comparison are you doing and why
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
Just to be clear, the code I suggested is generic, you'd just do checkProperty(Orientation, [valueOfCurrentGamesOrientation]) instead of checkProperty<Orientation>(currentGame);
because my project group s*cks *ass
I guess I don't understand why, if all these things are things you can check on any game, why is there not just an interface or common base class on which you can check these things on any game?
?
I'll try that. no worries
I just feel like having to defend some ass decision I have to work around with...
The first will generate this:
[CompilerGenerated]
[SerializeField]
private float <CurrentHealth>k__BackingField;
public float CurrentHealth
{
get
{
return <CurrentHealth>k__BackingField;
}
set
{
<CurrentHealth>k__BackingField = value;
}
}
The second stays the same as the source code.
I know the pain, I remember way back when I was studying game programming I had some shitty groups too lol
believe me... this is "the base" class XD
the others had it even more split up, before I stepped in
sounds like it needs further refactoring ๐
I'm just trying to find a more flexible solution, in case they come up with some new BS type I need to check
Like hell it does... I have to deal with codes written like a first year student does... .and then tell them "guys, I cant work with that"
One question, do you only ever need to check two games GameAsset files against each other?
in fact... it's 50 of them
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...
I'll try this
so you're looking to find which 50 games share the same value for a certain property, right?
and this
yes, so they don't mess with each other, either on screen space (because of different form factor etc) or by keys (avoiding same inputs)
Hoenstly sounds more like a "tagging" system would work better
probably too
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
best part is
they told me yesterday "well, we may end up killing the idea, but you first finish it"
instead of having individual fields
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);
}
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?
could be good
Use Debug.Log and check if your code is running (and isGrounded() is returning true, etc)
I just went with enums fo the others to be able to set the respective values of THEIR games in the inspector
really depends on how you're moving things
just a transform.position = tool.position
just after moving the camera
where
when
how
Show code
explain the components on everything
details matter ๐
public void SmoothTool()
{
if (toolInHand == null)
{
return;
}
toolInHand.transform.position = toolPlacement.position;
toolInHand.transform.rotation = toolPlacement.rotation;
}
it s what i showed yesterday
Yeah I don't remember what I ate for breakfast so
lol
do all of the enum field of a GameAsset have to have the same value for two games to fit together? Or do they fit when they have no similar values? Or is it something else?
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
for any camera movement, the only suggestion i can give is move camera in lateupdate()....
Btw
the suggested code is what I currently have... but on a "per property" basis
Will try to find a way to simplify it... It annoys me as hell having to check for each single one...
They fit if the value differs (in some cases) and in some it's better if they are the same (form factor and screen orientation)
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)
ah yes i did that, but the problem is the item that is jittery
Hmm, seems like a very messy project, yeah. I wish you good luck in not choking on all the spaghetti!
thx... when I picked it, I was VERY lucky as it encompasses everything I want to do later.
But working with people who don't get Game Design or basic ways of how senses work and cognition and cogintive overload... but just joined because "games = fun"
thx for everything.
I'll try some of the suggestions later.
Venting also kinda helped...
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?
i tried and its not showing isgrounded
what to do?
RaycastHit2D has an undocumented implicit cast to bool, it's just checking that the collider property is not null
https://github.com/Unity-Technologies/UnityCsReference/blob/master/Modules/Physics2D/ScriptBindings/Physics2D.bindings.cs#L3204
interesting, thank you
fix your grounded check then
investigate why it's not determining itself to be grounded
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
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Just repost the video here
I deleted it xD
Understandable! There were plenty of those in my game programming degree too, but they all dropped out within the first year after realizing the study required actual work and learning, and wasn't just a chill 3 years of playing games
This is very common. Most of them don't even last 3 months
Is there any way to build polygon meshes for sprites manually in unity or change the default one?
yep you can freely edit the polygon collider 2d shape
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
this is a weird/vague question
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
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
bind it to a lighter weight object
you can bind it to any property you want afaik
there you go - bind it to the async task's progress field
make a property that reads that
and bind your progress bar to the property
oh? ok ill try!
is there any people using photon fusion ? i've a problem how to run function StartGame when i load scene from addressables
So lets say i have a BaseTile class and a TrapTile class that inherits from BaseTile, does GetComponent<BaseTile>() also work on TrapTile?
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.
Okay cool
So you'd have to cast it later if there's methods not implemented in the base which you need.
good use case for interfaces, since any reference stored as an interface type will only be able to use the interface-specified methods
anyone knows how to add an audio in the script like footsteps, jumping and selecting weapons?
AudioSource.PlayOneShot
...how am i suppose to use that
!api
๐ป Learn in detail about the scripting API that Unity provides https://docs.unity3d.com/ScriptReference/
Not collider. I meant the mesh itself. Sprite mesh
Probably, I have to use external libs like texture packer
In code you can do:
https://docs.unity3d.com/ScriptReference/Sprite.OverrideGeometry.html
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)
Less triangles obviously
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
Hello guys, is it possible to overlap shader to draw one over the second ?
I would like to have only the red square.
do not cross post
Sorry
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?
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;
: UnityEngine.Object ?
this can never be null
well, it can but only in like an event you fail to unregister
im using UnityEngine.Object so that, a refrence in another object to a LaunchGroup can be null
oh i mean imim using UnityEngine.Object so that, a refrence in another object to a LaunchGroup can be null while LaunchGroup is [Serializable]
Mhm, no need to inherit from UnityEngine.Object
As long as it's marked as [Serializable] Unity will interpret it correctly
if you need weak reference use weak reference, im pretty sure such hacks will result in undefined behavior
Also I don't think stuff deriving from UnityEngine.Object, plus that are serializable, likes parameterized constructors
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
my B ill explain it from the bottom
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
its designed to point to a native object, implicit casts are designed for native object, directly inheriting it is a minefield
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
why
use weak reference
Asking about your attempted solution rather than your actual problem
whats a weak reference and whats lazy init?
actually i could prob do this or just overall set launchGroup elsewhere
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
From what I understand?
LaunchGroup lg = new(..., packets);
packets[n].launchGroup = lg;
yeah i can just do that
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
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
its pretty much what UnityObject is, but designed for c# objects not native unity ones
public LaunchGroup? launchGroup;
thats the same as just launchGroup reference?
I also want it to be visible in the editor, but making it Serializable makes it start as not null
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
i'm curious why you want a constructable object assigned via inspector
tbh I just want to see it easily without a having to put breakpoints and find the specific block I want to look at
what blocks
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)
idk what packets are. network packets?
you could add a gizmo that displays the group number/name
meteos is a falling block game, its basically a match 3 the packets being actual blocks as my game is themed around coding
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
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
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
so is it like, a "group" are blocks that get connected for potential removal?
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
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)
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
actually I have 0 clue how to make a combined mesh out of a bunch of squares
you don't
Oh wait nm i get what your saying
you iterate over and call Gizmos.DrawWireMesh on each block
yeah I realized you meant a foreach loop for launchGroup.packets
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
๐
how do i actually get the mech of the 2d Square game objects?
you can serialize a mesh reference and assign it. you can get an object's MeshFilter component and access MeshFilter.mesh
okay how would I just make a 1x1 square mesh to pass in as the blocks will never have a different mesh
[SerializeField] private Mesh _mesh;
then you can just assign the mesh that the cubes use
In that case, you could use the simpler Gizmos.DrawCube method
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?
Do your objects even have meshes? If they're purely 2D objects, they probably don't
IDK? i guess no? i specified 2d Square game objects hoping you guys would know
You need to look at the object's components to know
doesn't matter if you're just drawing a cube with gizmos
A Sprite Renderer does not render a mesh. Actually anything that doesn't have a Mesh Filter doesn't have a mesh
Ah. Okay so I'll just go with drawing the cube then
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.
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
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.
{
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 ๐ญ
That works. Make sure the code is getting executed and that there are no errors
what was wrong in the end? seems fine to me except no void @near rover
yeah I just messed up the syntax (missed a bracket)
turns out I was right
No worries, thanks!
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
i cannot read that shit
can you paste this instead of a screenshot
thats in the read me
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
does the script use Resources?
I
no
I'm thinking it's to do with assembly definitions?
are there errors
The type or namespace name 'TestCustomizerDD' could not be found (are you missing a using directive or an assembly reference?)
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
can constructors not work from monobehaviors or something
This icon I believe
Was there some kind of change
you shouldnt use a constructor for it
u mean instantiate?
I must have some reason I did it
or i guess add component can be used nvm
What, for a monobehaviour? Addcomponent works too
i was thinking of spawning an object
If you did, that thing probably didn't need to be a monobehaviour..
but it used to work which is weird