#💻┃code-beginner
1 messages · Page 402 of 1
well im back
I followed what you guys said earlier and did some more looking into C#, and im slightly confused on a specific aspect
I want to pass a function from one script to another, and I even looked at my other UI script and im still a small bit stuck
in my screenShake code, its all the logic needed for the screen to shake, I just want to call the shake screen function when the bird object collides with this object
is there anything im doing wrong here?
how do i switch a model
Looks fine on this end, what is the shake camera function on the other side?
hey look, im getting better!
okay lemme send that
More context please
i did
idk why u think I didnt try that lol
!code
📃 Large Code Blocks
Use 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 format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
switch a model in what way ? also where is the coding question part
Because if you had tried it, you would know if it worked or not, and not have to ask if it worked or not
i did try it
i said that
is there anything im doing wrong
i thought it would have something to do with coding
Just show the camera shake method
ob mb lol
Is there anything that leads you to believe you are? Is it working?
I LOVE UR PFP
switching out a model can be done in code too sure. It all depends what you're doing
It sure could, what are you trying to do

Is it working
if not, then probably
if yes, then no
we need a flow chart for this channel , of "have you tried debugging it first"
why isnt unity accessing my UI I have the using UnityEnging.UI; on but its not accessing my object resolutionDropdown
to be fair, I could make a new script for the shake
Okay, there we go, a statement of problem.
Log the tag of the object you're hitting in OnTriggerEnter2D before the if statement. See if you're ever actually colliding with something tagged "bird"
wait it would be easier if its jusyt one mb
you didnt create it
wdym didnt create it
What is resolutionDropdown?
what is reslutionDropdwon ?
@swift crag i dont think im doing this hash thing correctly. I'm getting replays that work, but the hashes are apparently mismatched.
https://gdl.space/iyidasejad.cs
you dont have anything in ur script that defines what resolutionDropdown is
You haven't declared anything called resolutionDropdown
i'm trying to change the model of something to make it into this and i have no idea how, it's for a joke
Quadrakill QuintupleKill!
if you hover over the red error, it will tell you it doesn't exist
gotta learn how to use VS and read the info it gives you
Export it as an FBX, import it into your project, and change the .mesh field of a meshrenderer to this one
I'd suggest adding a way to find exactly what differs
so, walk through both game states and log anything that mismatches
ohhh ok im following a brackeys tutorial and they got had no problems but i guess there was an update along the way ok thx for the help
I dont have blender on my phone but you can use FBX then swap it out there
I can guarantee they didn't use a variable they never declared
isnt that what the hash thing is for, though?
The hash makes it easy to check if two states are identical
You want to find out what isn't matching
even if its brackys 🙄
dont think they would just have that undefined var there
you missed a step
Declare this resolutionDropdown at the top as a Dropdown type object
ye I mightve be sleep deprived i missed that they made a variable already sorry
ok, approximately how long would this take for me to do?
follow the tutorial but better
im overlaying recorded videos of the original video and the replay and theyre literally frame perfect, could it possibly be that my hash implementation is wrong and im adding things in the wrong order?
probably like, a minute
that's why you need to compare individual parts of the game state
like, you could have just done that in the time it took to ask that question
trial and error a dying breed or what..
added the debug log. its adding score but not shaking screen
A hash is convenient to send over the network. But if you have two GameStates, why not compare them element by element?
i'll probably just do that, then. I'm not sure what else a hash takes into account when youre creating it but i feel like im writing the code wrong if the game is fine but the hash is telling me its wrong, or maybe its a floating point math thing
Can you show the inspectors of your CinemachineBasicMultiChannelPerlin component, and the screenShake?
Ok so this is some issue with the shaker code. Is it actually retreiving the cinemachine component? Add some logging over there and make sure each step of that function is behaving as intended
i can definitely do that
heres my virtual camera object
I assume I should put the script on the object that actually is being collided with right?
Well, there appears to be a warning on your Noise profile, expand it
see what it has to say
oh shoot
Doesn't matter, as long as it's properly referenced. If it wasn't you'd be getting a null reference exception
you probably need to start the AmplitudeGain at 0
okay i changed it
There should be a field in the inspector for it
lets see
okay so I made it 0, and when the objecy is collided with I get this error
All right, what's pipeCollide line 20?
i do that in the inspector right?
yes
However if I understand properly, this script is on the pipe
which is a prefab
so you can't
You would have to assign the reference at runtime (when spawning the pipe)
Or use the singleton pattern again like you did for the ScoreManager
mhm
now, im going to try and add sfx to when it collides. Im going to try and do it all on my own, and if there is a problem I will report back
thank you for the help so far. ur making a mans dream come true <3
See how much smoother this goes after a full night's sleep
okay im back BUT it should be easy and not a code thing
I added code so it plays a sound when it collides with the pipe, but it isnt playing the noise
the audio listener on the camera is on, the clip is even inside of the inspector slot
nvm it works, i had to add something small
lol
Does anyone know what the issue may be here? Im trying to make it so if Box Collider Collides with another there should be a message in console 🤔
but for some reason cant get it working 
!ide
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
• VS Code
• JetBrains Rider
• Other/None
- You haven't configured your !ide
- It looks like you have a function in your function
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
• VS Code
• JetBrains Rider
• Other/None
Is this what I need? 🤔
this is one of the many steps you need to do yes
did you click the link
!vs
If your IDE is not underlining errors in red or autocompleting code,
please configure it using the link below:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
The steps are clear ☝️
Follow all of the steps. Do not skip any of the steps.
If I have to use visual studio community instead of enterprise (what I have been using) will it still be the same? / will I run into errors with my code? 🤔
If you have enterprise, just use that
it wouldnt let me modify to add the unity stuff 🤔
uhh nvm I think I got it 
@swift crag after serialising both the recorded state and current state, i can see some non-negligible discrepancies. could that possibly be because of script order execution or?
That is very possible. You need to ensure that everything happens in a very explicit order
everything related to characters and projectiles i hope you mean lol
You could do this by setting script execution orders for everything, or you could explicitly run update methods on everything
cus i've got like 200 scripts 😭
and, in fact -- if you want to be able to do rollback eventually, you'll want to do the latter
Although, actually, if everything is using FixedUpdate, you'd be calling Physics.Simulate() manually anyway
so FixedUpdate would be getting called
honestly for now, i'll just do script execution order stuff
does it matter if I dont set the order for things like UI and other things that arent integral for the game simuation?
That stuff doesn't matter, no
although, you do probably want to update the UI after the game state is updated!
otherwise it'll be a FixedUpdate behind
(But you probably want to update the UI in Update anyway)
You need to separate your game state from the presentation of the game state, basically
i'll do character simulation first, then projectile simulation, then whatever else i need to check what is important here
i guess i'd need to update the kinematic character controller after the character
because the character decides the velocity basically
this aint working, Any Ideas? also the "Unity API Reference" doesn't show up under help 🤔
Show your External Tools settings, as well as the Package Manager window.
where I find those at 
I thought you followed the instructions you were linked to.
So what did you open for the step that had you change the external tools settings
The instructions very clearly instruct you to go to both of these places
Then you would know where it is
I see one sec
I don't know how much more clearly I can state this #💻┃code-beginner message
Okay, both look fine.
Close Visual Studio, click "Regenerate project files" in the External Tools window, and then double-click a script asset to re-open Visual Studio
best to delete the .sln and .csproj files in the project
yes -- those are the files that Unity generates
they shouldn't need to be deleted, but, you know,
I've seen it be a problem before.
well the .sln is not always regenerated when switching from VS Code to VS
or vice versa
i rename and move projects around a lot.. i always delete my .csproj inbetween
i need some help i put a code in unity or whatever and i tested it and i can walk but when i do when i stop pressing the w key to go forward it keeps going forward for like 1 second
alright did that, I don't know if "Regenerate project files" worked or not as when I press the button nothing happens 
but im back in visual studio and I dont think we working still 
Now reopen visual studio, do you have errors underlined in red now
umm, I dont think so??? 😭
Do this, then regenerate the project files again #💻┃code-beginner message
If the issue persists after that, screenshot your entire Visual Studio window.
alright
That isn't your entire window.
When you don't know what you're looking for, you should err on the side of providing too much information
my bad I was screenshotting the code because digiholic asked if my errors where underlined 😭 🙏
ah, I see
so delete the .sln here?
yep and the .csproj
Yes, along withg the "Assembly-CSharp" project file.

Ignore
Ignore
You already know there's compile errors
aight this is my visual studio now 🤔
Still not configured
Select View > Solution Explorer and take a screenshot again
you're looking for the "Miscellaneous Files" indicator here: that means Visual Studio doesn't think this file is part of a project
and yes, that's the next place to look
Right-click the Assembly-CSharp project and select Reload With Dependencies
Yes, there you go
At least... somewhat? The error still isn't underlined
But it's highlighting Unity stuff at least
Uh I think we workin now
Ah there we go
Now, onto the second point:
You got a function in your function
not gonna lie idk what this means 🔥 🗣️ 💯
It means you have put a function inside another function
OnTriggerEnter COULD be in Update if you remove the word private. But Unity will not call it from there
So remove it from Update
unless you are absolutely certain you should be doing that, it's usually a mistake
im just following a youtube video 😭 🙏
This is not what they did
I guarantee you that
Then you should follow the video, because they certainly didn't put a function in a function
Zoom out, that is not the issue
Show their full script
Can you quit spamming the emojis before I have an aneurysm
The issue is that you put it INSIDE of Update
See how it is very different
notice how this is not inside of an Update method
Stop
I can't wait for summer break to be over.
"I did it exactly like the tutorial so why does theirs work and mine doesn't" counter:
Number of times it wasn't exactly like the tutorial: 168
Number of times it was exactly like the tutorial: 5
Number of times the code literally did not exist: 1
2022-07-19 to 2024-06-27
Yes. Because you put it in a function
am I just stupid??? 😭
Again, you are looking at the wrong part
And they did not
It is INSIDE OF UPDATE
Fucking stop with the emojis
my bad my bad

I meant to ask, did you make a server to get your own emojis and use them everywhere?
I have a server for my randomizers, streams, and minecraft server
Nice
but I have added emotes solely to use in this server
I knew it

how do i make the green thing aline with the plane? cause when i press play and i walk on it i cant walk on the plane i just walk on the green thing
Show me how the "Scene" object is scaled.
wdym like the whole thing?
dont scale ur root objects
No. I want to see the scale of the "Scene" object.
It's the object named Scene.
Show me its inspector.
its probably whacky.. you heard it first here 📺
booya
There's the problem.
what i do?
You have a non-uniform scale on a parent object.
When you do this, it causes skewing of child objects that are rotated.
As the child rotates, it lines up with the X/Y/Z axes of its parent differently
causing it to distort as it rotates

The Box Collider component cannot deal with this properly.
if ur parent is 1:1:1 rotations and sizes will be fine for the children
it winds up separating from the visible cube (which does skew "properly")
if u scale the parent to something weird the children grow up to be something weird
don't do that
make its scale uniform
e.g. [3,3,3]
don't scale the root object ... if u need that collider thats on it to be scaled weird
I'm trying to use courtines to make the player only able to jump once every 10 seconds. Anyone know why this isn't working ?
{
StartCoroutine(JumpCooldown());
}
IEnumerator JumpCooldown() {
// if jumped, wait for a second
if (Input.GetKey(KeyCode.Space) )
{
ball.AddForce(jumpForce * Vector3.up);
yield return new WaitForSeconds(10);
}
// otherwise wait for a frame
yield return null;
}
make it a child and scale that instead
This starts a new coroutine every single FixedUpdate
how do i make it a child?
These are child objects.
u already have children.. u should know how..
If you don't know what any of these words mean, you need to stop what you are doing right now and go use !learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
- parent
- child
- grandchild
oh i see. So I should start the courtine in start()? or is therre another way thats better practice
Each coroutine individually checks if you hit space. If you did, it adds force, waits 10 seconds, and then ends
That would not work either, since the coroutine would run once, then end.
Consider a coroutine that just resets a field back to true
bool canJump = true;
IEnumerator JumpDelay() {
canJump = false;
yield return new WaitForSeconds(3f);
canJump = true;
}
If you run this with StartCoroutine(JumpDelay()), it'll instantly set canJump to false, wait 3 seconds, then set it back to true.
yep
issue building? compiler is closed
I don't know how you would "close" the compiler
are you talking about the console? your code editor?
yes thats what i meant sorry
That doesn't do anything.
Look in the bottom right corner of your editor. There will probably be a blue bar with some text on it
e.g. "Compiling scripts"
lol, im just really tired sorry, brain isnt working and i just want to build this
that means Unity is busy doing something
ive restarted unity
looks fine now
i press build, same error and this pops up for half a second
Always look at the first error
The other errors will just be "the build failed"
your code has a using directive for something in UnityEditor
None of that stuff exists in the built game
red ❗ are a no-go
It was probably added by mistake.
Try removing the using UnityEditor... line from the script.
vsc would usually tell me theres errors in the console with a big red notification, didnt realise i had errors since i didnt check, thats on me!
yup, no worries
The sneaky part is that this error only exists when the game is built (:
It's totally fine when working in the editor
It's (very very roughly) because of some code like this
#if UNITY_EDITOR
public class Oops { }
#endif
#if is used to conditionally include parts of a script
i havent got the using UnityEditor line
this only includes the Oops class if UNITY_EDITOR is defined
line 3
I don't understand why but my character randomly starts rotating around 360 degrees when I stop moving. Any idea why? Must be a simple issue but I've been coding for almost 20 hours now and I have burnt every brain cell 😔
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
no prob (:
worked just fine, thank you so much
How can imake something like this work in unity?
List<GameEvent> events = data.BeginTurnCardEffects.Select(x =>
{
ITarget target = null;
if (x.needTarget) { target = GetTarget(); }
return x.CreateEvent(data, target);
});
Nvm I figured it out, just added a rb.angularVelocity = Vector3.zero; in the else and it worked
why doesnt my icon change?
Did you build it again after changing it?
Because that icon if used for the built game not the project
i deleted the old build and then built it again yes
Sometimes windows Caches the old Icon for some reason, happened to me once and a restart showed the new icon for me.
did you not see the little check box?
the override one? i tried that
^ this, when i transferred to a usb it sorted it
That's used to provide a specific icon on desktop platforms, so that would not be helpful here anyway
does changing base class script execution order change inherited clases script execution order?
if you use the DefaultExecutionOrder attribute, that should be inherited. i don't think that just changing the editor setting will do it though
this reminds of a tangential thing: it'd be nice if there was a way to completely scramble all of your unity objects so that things with the same execution time now run in a different order
to help catch really weird execution order issues
are these just orders or like ticks or something
The numbering system? It's just arbitrary numbers used for order
ah i see
I wonder which would catch more bugs more often:
- A random scramble
- Reversing the order
the discrepancy is getting shorter now
but its still there
not sure if this order is optimal
Or shuffle, see if theres still errors. If so, close the application. Quantum bogosort
What's the best way to enqueue events?
I feel like i'm reinventing the wheel a bit with my event classes
What do you mean best way? This sounds like you just want to store them whether that be in an array, list, queue, whatever, or even just all in one delegate.
Yes, but i'm implementing my own event classes
and it's been difficult
I'm watching a UnityEvent tutorial on youtube but i don't know if it has applications outside the inspector
Then share the difficulties. Queueing up events alone doesnt seem to be the problem
Unity events are pretty much just for inspector
Hello, can anyone help me resolve this error?
It happened right after I installed the package for In App Purchasing
System.BadImageFormatException: Format of the executable (.exe) or library (.dll) is invalid.
at Mono.Cecil.PE.ImageReader.ReadImage()
at Mono.Cecil.PE.ImageReader.ReadImage(Disposable1 stream, String file_name) at Mono.Cecil.ModuleDefinition.ReadModule(Disposable1 stream, String fileName, ReaderParameters parameters)
at Mono.Cecil.ModuleDefinition.ReadModule(String fileName, ReaderParameters parameters)
at ApiUpdater.MovedFromOptimizer.Program.CollectMovedFromTypeNamesFromAssembly(String assemblyPath, StreamWriter outputFile, IAPIUpdaterListener logger)
at ApiUpdater.MovedFromOptimizer.Program.RealMain(String[] args)
at ApiUpdater.MovedFromOptimizer.Program.Main(String[] args)
not quite sure what it means.
Ok
i'm gonna take a dinner break then I'll come back with more questions 🙂
im have a button setup with a onclick but my function wont show up when i try to find it ik im prob jsut dumb but can someone help
did u drag in a gameobject w/ the script or did u drag in the script itself?
wdy,
yes i draggewd that one in
Drag the gameobject into the spot where it says none on the onclick function.
thats wrong..
u cant drag the script in there like that
u have to drag in a gameobject w/ the script attached to it
the script doesn't exist just because its in the project folder
thers no object to drag in another gameobject
@rocky canyon are you able to help me with my error im facing?
the slot
so put the script on a gameobject
this one.. drag a gameobject in there
if u dont have a gameobject w/ the script make one
¯_(ツ)_/¯
components need to be on a gameobject
yes they are, and no they dont
cause I cant find the fix to my issue lol
no, sorry i can't help you with this.. im not familiar with mobile or / ad type stuff sorry
anyone know why this happens? was fine before but now its almost impossible to write code without writing over something else 😭
press Insert on your keyboard
preciate 🤝
the game freezes up for a bit when i try to load from disk, is there a way to make this async or coroutine to let it load replays in the background?
amazing 🙂
ReadAllTextAsync
ig
unsafe? lol
why is it unsafe
cause its lowlevel
could i fuck something up with this method
public unsafe void
never seen that keyword before
This is worth trying too
so it lets me use pointers
this is what imean @rocky canyon
You cant put scene objects in a prefab
thats a script not a scene obkject'
unless thats just bad screen recording im seeing
you're not supposed to drag it from project folder..
same; i haven't touched this before
would love to test it with big file
and how do you mean that
does this i have to use async methods or can i put it in a coroutine or
it needs to be on an Instance of a gameobject to run, thats how components work
no clue, my first time seeing this. the link i sent seems to be doing it inside Update so idk whats going on
What does that mean im very new
uncharted territory
interesting
u dont drag in Apple.cs you drag in a GameObject w/ the Apple.cs script attached to it
as said 4 times already
@queen thicket Scripts that are Monobehaviour are components. Components need to be on a gameobject to do anything.
☝️ this
what i was poinng out was that it dosent show my function in the onclick thing id think thats what you guys are talking about it onbyl shows monoscript when i want it to show speedpotion functions to
we know what we're talkin about..
its because you're using the file from the project folder, and thats not correct
thats just a textfile by itself 🤷♂️
The text file containing the code does not have functions. An object with the script on it has the functions
ok well i was confused because before i had done it just like that and it worked perfectly
Create a New GameObject
- Name it SpeedPotion or w/e
- Attach the speedPotion script to it
- Finally.. drag that gameobject you just created into the slot
No, you haven't
press X to dougb
wish had nitro still
dougbt
At no point could you ever drag a script object onto a UnityEvent to run a function defined by the script
You've dragged in a reference to a script asset.
i gotchu
This is like trying to drive the blueprint for a car
ok
writing calligraphy w/ a squid
you also can't reference scene objects w/ a prefab
unless that reference is Inside the prefab already
ok well then this tutorial im following is not doing a good job
sooo.. you should put that gameobject u made inside the prefab.. and then try assigning it
what tutorial are you following?
In the second and final episode of the mini inventory tutorial series with Unity and C# I'll show you how to get your player character dropping items from his inventory back into the game world as well as use those items !
SUPPORT ME : https...
i did the first one aswell
you probably followed it wrong
Where in this video did they drag in a script file to a UnityEvent?
what did he make the prefab from?
the gameobject w/ the script attached to it
ok ty for helping someone who has no brainpower what so ever
careful how many times you run LINQ esp in unity
In the second and final episode of the mini inventory tutorial series with Unity and C# I'll show you how to get your player character dropping items from his inventory back into the game world as well as use those items !
SUPPORT ME : https...
watch from 5:36
why? im only running it like once a scene anyway so
ooh thats fine then. I mean things like Update or consant operation like that
for loops are always best in that case
wait nvm my code is (idk if i can swear but you know what i mean)
.Last is fine, it shouldn't generate garbage if that's what you mean
But yes one should be wary of Linq methods
just mean LINQ in general but yeah .Last is not biggie
||ur code is Fucked up eh? ||
trying backing up, and taking it a bit slower.. and pay attention to every move he makes
nah its just ||shity||
it happens...
we all write shit code at first
it gets better the more you practice
this si my problem if you need the error its NullReferenceException: Object reference not set to an instance of an object
speedPotion.use () (at Assets/Scripts/speedPotion.cs:15)
UnityEngine.Events.InvokableCall.Invoke () (at <10871f9e312b442cb78b9b97db88fdcb>:0)
UnityEngine.Events.UnityEvent.Invoke () (at <10871f9e312b442cb78b9b97db88fdcb>:0)
UnityEngine.UI.Button.Press () (at ./Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/Button.cs:70)
UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at ./Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/Button.cs:114)
UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at ./Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/ExecuteEvents.cs:57)
UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at ./Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/ExecuteEvents.cs:272)
UnityEngine.EventSystems.EventSystem:Update() (at ./Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/EventSystem.cs:530)
Working on inventory is fun til you try saving and loading
ohh.. that IDE doesn't look too configured to me..
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
• VS Code
• JetBrains Rider
• Other/None
ikr it sucks having no intelliscense
if you did things correctly your items would already be the proper formatted objects
pushing my entire project folder to git is normal right?
saving and loading is the best thing i ever done
Not everything in it
notably, the Library folder is excluded
I also followed a tutorial and dont have the slightest clue of what information to keep T-T
!vc
Unity Version Control
Git
Get the latest .gitignore file from here. It should be placed at the root of your Unity project directory.
are you using the unity .gitignore template
sigh
nah i just commited the folder 😦
if u push ur Library folder get ready to wait a few hours
thats probably why. Once you build your own system by scratch by yourself, you will know exactly how to serialize it to a file
Lost all my old projects so it seemed logical at the time
if that was your first commit, i'd just nuke the .git folder, re-init the repository, add the .gitignore file, and commit again
it's probably easier than rewriting the commit in that situation
Yep you're right
can you tell what it is from the video i dontknow how to do it
sure
public void Save()
{
// ERROR CHECKING
if(!Directory.Exists(Application.persistentDataPath))
Directory.CreateDirectory(Application.persistentDataPath);
// create json // pretty print cause line breaks for readibility
string jsonObj = JsonUtility.ToJson(_saveData,true);
// write data
File.WriteAllText(saveFilePath,jsonObj);
FlashSaveActivityIcon("Save System: JSON-W");
}``` w/ JsonUtility ofc 😉
JAYY SON
im good enught with file handeling and stuff and i could make some devius spegethi code but i jsut dont know the unity stuff
I remember the hassle of learning this for pygame ( I don't remember shit)
Serialization requires you to turn your giant blob of C# objects and references into a neat little file
It is non-trivial.
its all in one.
Null reference are not "unity stuff"
i cant even find a speedPotion.cs in his tutorial
i skimmed the first one and the second one
hey guys! My game is pretty close to completion from what I can tell. I have a really dumb question and I know I asked it before kind of but im still confused a small bit
its not in his tutorial i made it myself 😢
there is no magic bullet for good save systems, you really need to consider what data needs to be saved vs just reconstructed state
okay so, I want to take the value of lives from another script and put it into a different script in an if statement. do I use parenthesis and if so where.
theres only two possibilities.. either you dont have a PlayerMovement assigned (which i don't see it getting assigned anywhere)
or theres no variable called runSpeed
wait what do i assighn it as
if statements require parenthesis yes..
make it [SerializedField] priivate PlayerMovement movement;
and then you can drag in the component in the speed script
== 0
= is for assigment
lmao
and u sure ur comparing the right thing?
shouldnt it be lives.lives == 0
rather than the Type
Please do some c# basics first. This isnt even the same thing
One is a variable of type LivesManage and the other is a number.
my heads about to explode
im sorry 😭
its not you in particular
okay good lol
i get errors cuz im stupid [SerializedField] private PlayerMovement movement; with this
Also need to compare not assign, and is it static or a instance field
you can't make everything static , you have to learn how to make references and connect them
ok this time i swear i followed the tutorial exactly and i have 6 problems from 3 lines of code
okay ill look into it rn
can u screenshot the script
Trying to add a score system to my game. Does anyone know what the errors mean? 😭
also what is the error , screenshot
You can't have two things with the same name
naming a method "Score" is strange..
Methods make more sense when named as actions. Maybe AddScore?
method name should be similiar to an action or something
no d on the end
it dosent 😢
erm what the sigma its still giving me the error 💀
look
you need a configured IDE if you plan on getting help
now u need to assign it man
see the None u need to put the gameobject in there that has the PlayerMovement script
and by now u should know how reference work (sorta)
ok my dumb ass frogot about that one cheif
attributes use brackets, not parens
huh
im so done right now 😡
not a clue what that is
can you avoid this by setting requireded components?
mine... correct
the thing you're using..
its an Attribute
yours wrong
Where did you see to use (
im using like 50 things
absolutely.. he's struggling so i wanted to make it simple
but u should assign it internally in the script when u can
I just told you what, its called an Attribute
maybe he's talking about the thing you're having problems with
I DONT KNOW WHAT THAT IS
had you bothered googling it you would know what it is
Try watching someone build a project and following along
Thats exaclty what i did
ohh you mean like @dusty shell
right, but you used parens () instead of square brackets []
I dont thinkk they even understand why they need to use brackets..
you need [AttributeName], not (AttributeName)
ya, if the script was meant to be on the same gameobjec thats fine @dusty shell
(that's a separate convo)
but his script was on a different gameobject
oh wops myb @rocky canyon
mf maybe a 30" monitor still wasnt big enough for a quartered screen
yes
thank you that guy
im 😭 rn
"Hey man what is this thing?"
"That's called an 'Attribute', here's a picture of it"
"I DON'T KNOW WHAT AN ATTRIBUTE IS SIR I AM NOT A COMPUTER PERSON"
christ, calm down lmao
google exists for a reason, there's a ton of info for you out there
ya, but i dont think his Movement script should be on his speedPotion
don't just copy their code tho
camelCase classes 😢
im setting the speed varibal
i was talkin to JoJo
ive been coding for 12 hrs straight im a little bit tired rn
the studio was saying tuple so i assumed thats what it was
na
time to take a break then
i gotta get it done
lol.. okay then
right, because you wrote that instead of an attribute, which is why it was wrong
Right, because what you wrote was a Tuple. With parenthesis. Which don't go there
otherwise my dad will go and get the milk
is that some gen z cryptic lingo?
I remember my first beer too
guys is unity easy to code games in?
only if you can learn C#
The main thing is, I'm using the Command pattern in order to make my card game events because I initially thought that C# events aren't synchronous and I also thought that it would make my code "cleaner" but it's been so difficult to implement that I've started looking to other resources and I also realized that using Command or not is just a design decision.
depends on what you consider "easy"
if u have a moderate IQ level its prettty ez
i can becouse why not
no my dad said he would leave if i dident finish this project today
lmao.. craziness
it's a skill, you have to actually put effort into it
then depends on how quick you learn and whatnot. there is no gauge for us to say
i learned a bit of rust in week
its all RELATIVE 😉
ok so what unity version should i start coding at?
And I also realized that undoing commands isn't something common to the game that I want to make, so I'm not finding many reasons to keep developing my Command pattern.
@eternal needle
2022
60000.0.7f1 or 2022.3.34f1?
the latest LTS version
how can i change install loction, arch linux
60000 could have issues u might not be able to deal w/ learning
through the hub
would hdd work?
sure
not too bad @rich adder
can i later move it to ssd?
oh interesting
🖕 I figured it out thanks for the help.
my dad said if i started learning programing that he will buy me better gpu and bigger ssd
only when I load initially it may take longer than my SSD versions
but once its loaded up its not noticeable to me.. from my SSDs
ookk lol No idea why you took that statement so personally
Although, at this point, I could keep at it just for the sake of finishing it.
@eternal needle
daaamn, he went savage on u
time to get going then
do i need windows to test games in windows or testing linux version is enough?
depends on who ur target platform is for
pc in general
then u probably want to test on windows from time to time
if u can
and Mac.. but i can't even do that
i can if the games will work on 10 years old gpu
my friends aint rich enuff
im using a 5 year old GPU
no issues
just buy rx 580 and hackintosh
gross
same the gpu i use in linux is 5 years old
lol.. sorry im just not a Mac fan
but my windows gpu is 10 years old i have gpu passthrough
i don't care if my games work on mac
its not about would they work on mac
its about arm
windows is moving to arm as well
and i only have x86 pcs and laptops
not me im not
i wish it was easy to run arm windows games on android
as how easy it is to run x86 windows games on android
i dont understand really why you'd want to run any games other than mobile games on android
just get a Surface and be done with it
how easy is it to port games to android?
it would be very intersting to make android game like the ads you get but at the same time have pc version and maybe steam version
😔
technly i can run mac os but without gpu
i might make an exception if someone paid me enough 😄
relatively simple.. you'd just need to change the inputs.. and nerf the graphics a bit..
if u use the new input system u can probably make an input action map that would work for both PC and Mobile
i mean couldn't you just add web support lol
id do that for ya guys 🙂
flash player was good
webGL builds are harder for me than regular builds
hard af to get them working as good as good as standalone build
compression issues, graphical glitches / artifacts / weird shader issues.. or just incompatible
so is triggered when i press the key or is it started?
im confused abt this new input system
performed i think
isnt performed when you press and release?
possibly.. im still learning too
lol we all are
i need to debug my test class and see for sure what happens
thanks for the help
[Serializable]
public class SomeClass
{
public SomeClass()
{
// when does this get called?
}
}
public class SomeOtherClass : MonoBehaviour
{
public SomeClass SomeClassInstance = new SomeClass();
}
okay so im still a bit confused. in a script that has the lives counter, I want it to play a transition that I made in a different script when lives == 0
Hello i need help, I try to do that my player slide on the wall :
if (isSliding == true)
{
rb.velocity = new Vector2(rb.velocity.x, Mathf.Clamp(rb.velocity.y, -wallSlidingSpeed, float.MaxValue));
}
I know that isSliding is true but my player drop on the floor normaly, my rb.velocity is false ? (the if is on void update)
For a Button-type action, it fires when you pass the acuation threshold (so, when the button is sufficiently pushed)
ohhh i see
thanks
For a Value-type action, it fires whenever the value changes. It might also fire when the input returns to zero (I don't use events for value type actions)
I just directly read the value as needed.
I know I can reference the transitionController script, but Im getting this error
when it's constructed
that's its constructor
new Classname() is the constructor call
bool interactable;
public void OnInteract(InputAction.CallbackContext callbackContext)
{
if (callbackContext.started && interactable)
{
Debug.Log("Interacting");
}
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.CompareTag("Interactable"))
{
interactable = true;
}
else
{
interactable = false;
}
}
theres nothing wrnog with this code but the interactable bool wont set to true
well, if you enter another trigger, you'll get interactable set to false
Make sure the tag exists
even if you're still overlapping the interactable trigger
Does unity have like complex assets?
that seems wrong
I don't know what that would entail
Like movement script assets?
it does
Complex ones?
i recommend KCC
Oh, like stuff from the asset store
there are only 2 objects in my scene though
what do you mean by "complex" though
https://assetstore.unity.com/packages/tools/physics/kinematic-character-controller-99131
i use a paid one.. but this one is almost as good
chcek it out
This is probably not a good example but it’s the only thing that comes to mind, apex for example
...the game?
no.. u wont find those unless there are some paid ones
u have to take a base controller and build it up
Yeah the movement in apex
https://assetstore.unity.com/packages/tools/animation/traversal-game-creator-1-179526 you'll find some that might have some of the features..
but no.. u wont find a 1:1 apex controller
Yeah I wasn’t expecting that but something similar is quite nice
what could I use instead of void?
WaitForSeconds needs to go in a coroutine
i don't think messages can be coroutines
you can't the message must have a void return type
nothing.. thats what OnTriggerEnter2D is
best you can do is define a seperate coroutine and start it within that message
You can't put a yield return in a method that returns void
would keep most of the code in the OnTriggerEnter and just move the SetTrigger, WaitForSEconds and load to a coroutine and start it from there
OnTriggerEnter --> StartCoroutine(TriggeredCoroutine());
so I out the StartCorotine instead of Collider2D and other?
u could pass those into the coroutine if u needed too.. but what passerby said is what i was thinking..
okay ill do thagt
void OnTriggerEnter2D(Collider2D other)
{
StartCoroutine(HandleTrigger(other));
}
IEnumerator HandleTrigger(Collider2D collider)
{
yield return new WaitForSeconds(1f);
Debug.Log(collider.name);
}```
like 
okay now do I type yield HandleTrigger?
how would I call the HandleTrigger in the OnTriggerEnter function
Hey! Is that code you wrote because seems interesting for interacting with doors and items like I understand right because I never used that method
normally
and then start it as a coroutine
its really basic interacting methods
wait lemme show u what I have
and yeah i did right it
@wooden socket go check how coroutines work
ok
Is it for a horror game?
nah
I am currently making a short psychological horror game, and I really have to watch tutorials on how to make interactable items and doors etc
thats cool
good luck man
they are easy to make but using them requires using reflection
for the most part its as simple as making a class that extends from System.Attribute
your constructor args become the args you can pass into the attribute on usage
using them requires more work
accessing the constructor args is also mildly confusing
i thought you could just assign to fields on the class at first
whats confusing, i always just have constructor args that have it to set a bunch of readonly fields
i use them in a few cases in my project, like register action types with the behaviour editor
and for stuff like building the debug/cheats menu
I wonder if I'm just mis-remembering another error I made
because I'm looking at https://learn.microsoft.com/en-us/dotnet/standard/attributes/writing-custom-attributes and that looks normal

can get the attribute info back easy with either .nets GetTypes GetMethods etc
or via unitys TypeCache if its for editor stuff
what is reflection
a meta coding feature
reflection lets you ask questions about types
like "what fields does this type have?"
It's how Unity calls things like Update
lets you do stuff like see what fields a type has, or what methods it has and invoke one etc
notice how it's not protected virtual void Update() or something
as long as you have a method named Update, it works
reflection is not very performent
I guess that's the simplest way to explain it: accessing things by name
its best to avoid in alot of cases
It also ruins static analysis
"who calls this method?"
"I DON'T KNOW"
speaking of, pro tip
if you do need to use a method name, do this:
yeah my only case of invoking via it, is for cheat menu, but since i use rider i can use its attributes
Invoke(nameof(Foo), 3f);
neat
all of my other reflection usages are editor time only, and for tooling
This is much better than Invoke("Foo", 3f)
My main use of reflection is a horrifying class that checks for missing references
while (parentType != typeof(object) && parentType != typeof(MonoBehaviour) &&
parentType != typeof(ScriptableObject))
{
fieldInfos.AddRange(parentType.GetFields((BindingFlags)(-1)));
parentType = parentType.BaseType;
}
yum
but yeah my cheat menu builder uses a ton of it and is complciated since it needs to build ways of setting up the proper UI per type, and for executing methods with args and passing stuff to properties
@stuck palm what is your usecase, and is it wanted on types, or fields or methods
ah yeah then the article i posted should be good, but also look at the TypeCache in unity, it has some stuff realted to how unity does it in editor
also
https://docs.unity3d.com/ScriptReference/PropertyAttribute.html
for cases where you want it for custom property drawers based on attribute
think of things like the Range(0f, 1f) etc
If you could rate... How hard is integrating inventory system with save load system for beginners like me? I started to question if I have negative iq or something
Without much experience programming hard. But things get easier at a fast rate as you gain experience
inventory systems and serialization can be remarkably difficult
why does default loction has to be in /
it gets easier if you simplify your design, such as by...
- having a fixed set of items (more like "key items" in Pokemon, for example)
- having non-stacking items
- keeping the items simple (no upgrades and modifiers)
i only have 120gb ssd it cant fit anything
it become 0bytes free from unity packages
Thank you for your responses. I was just curious how you guys see it.
changing loction redownloads what it has downloaded
i mean...everything has to be in /
did you mean to type something else
Yeah like things got real complicated when prefabs and scriptable objects got involved 😄
I am exploring that kind of thing now
I have around three years of Unity experience and a decade+ of general programming experience
cos what I understand from serialization is that I have to use the most basic types to be able to serialize them.
You have to be able to go from your game data (which is very very easy to make complicated) to something you can write to a file
That's why key items are relatively easy. You could even just write a list of item names.
nothing is too hard!
i dont have space in / right now maybe later when i buy 1tb ssd
You only need consistency and patience.
collision count is in another script
Don't worry, I'm a total begginer at Unity and I've been feeling overwhelmed since I started it
You got it!
how can I solvle this error 😭
/ is the root of your filesystem. everything is, by definition, inside of /
I see that you're trying to point the download cache to /mnt/hdd/...
well...create the variable
Item names you mean for identification?
Right.
Why do people keep their keys and values in seperate lists instead of dictionaries btw?
i think I fiixed it
unity doesn't serialize dicts, that might be why
Not everyone does that, I don't at least.
i really want to learn unity, its my dream to create game
but newtonsoft's json serializer does it right?
if you have the programming experience, i would go for a manual serialization strategy,
- create a map somewhere of keys to prefabs
- when saving, loop the items and write the keys to a file
- when loading, loop the keys of the file and instantiate the prefabs by looking up the key in the prefab map
- bonus: assume all the values not in the save file are "default" prefab values and save the "changed" values to the save file to apply them to the prefab after loading
That's a separate thing.
thats how i do it anyway
Unity serialization lets you store data in scenes and prefabs and assets
i wouldn't recommend it, but it's a workaround ive seen proposed
i'd recommend a list of structs instead
OO so thats a different thing okay
Json.NET is used to turn C# objects into JSON, and then from JSON back into C# objects
They both do similar things -- turn objects into data and back
You need something to be Unity-serializable if you want it to appear in the inspector
i keep getting null reference exceptions
well, fix them!
find out what is null, then figure out why it's null
Okay so that kind of explains why I got confused about ISerializationCallbackReceiver. Its for unity not c# serializer?
well, null is an object isnt referenced
but idk how thats possible
heres line 25 which is what its talking about
I think it would work after reading game data from json too though
the OnAfterDeserialize method I meant
if you are doing a load/save game system, just note that it is completely separate from the Unity scene editor serialization
borderController is null
the two are not related other than that it can both involve serialization
damn okay this makes things clearer now
It's used to manually fix up an object after Unity deserializes it -- so, after it's loaded from data
The example in the documentation is for reconstructing a dictionary out of two lists
Unity can't directly create the dictionary for you
But, given the lists, you can figure out the rest
Ah okay. Thanks. I must do more research on this
Shit is hard when you dont even know what you dont understand hehe
True Knowledge 😁
well yea, but idk how to fix it
lemme look into it first
Set it to something, instead of having it be nothing
So you've declared a variable. Where do you put anything in it
would i put the value in it in the same line?
Which BorderController do you want this variable to hold?
Well, which BorderController do you want this variable to hold?
You never answered that
BorderController is the other script
Okay but that script could be on thirty trillion objects for all this code knows
I want the value called collisionCount to be passed here
which one do you want
collisionCount
Which specific instance of the BorderController class do you want your variable borderController to hold
yoo, My score text is below my road sprite for whatever reason. Im unsure on how to fix it. My Score canvas is higher on the hierarchy also.
^ when I drag the 0 down it goes under the road
show the inspector for the canvas and for the road object
also, this is not a code problem
so show them in #📲┃ui-ux
there is no instance
its just a script
Show us the BorderController script.
!code
📃 Large Code Blocks
Use 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 format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
my bad ill ppost them theere now 
Then it does not exist
If there's no instance of BorderController then it is completely identical to if you had simply deleted the script
A script is merely a blueprint for an object. Until you actually make one, the script is worthless
If there are no instances of BorderContorller, then your field will, unsurprisingly, always contain null.
but its on a object
what is

