#💻┃code-beginner
1 messages · Page 710 of 1
Let's keep it in your thread.
Hello
I was wondering on how to use the Cursor.Lockstate, CursorLockMode and Cursor.Visible
Should I put those in Update() ? Is there a "best" practice to know ?
I tried using those lines in Start() but at runtime in the editor the cursor wouldn't lock or hide so I'm curious
You put them in your code at the moment you want to change it
In the editor this will only have an effect when the game window is focused
the game window is in "Play focused" , that's why I don't understand why it doesn't lock/hide
you have to actually click into the game view window to focus it
if it is still not working then you need to make sure this code is actually running
I've seen people say that on the forum , but doesn't work too for me
and the script is properly set on an active gameobject in my scene, I'm very confused
I put a debug.log message to see if it was firing properly and it did yet the cursor state was unchanged so I'm wondering if I'm missing something to know about it
either you are not actually clicking into the game view window or some other component is unlocking it
you might have other code changing it
How should I handle all of the scripts in my simulation(e.g. physics script)? Should I use a monobehaviour script attached to some object?
this is a really vague question so it's hard to give a specific answer.
in general yes you will need at least one MonoBehaviour as a code entry point in Unity to orchestrate your game logic.
But I heard there are also scripts that don't need a gameobject
Beginner here but should just be able to run a check if it's focused unsure if it's possible to allow a check of the editor itself or not, feel like this could be useful in some cases.
you can write whatever C# code you want. There is no limit.
But again, you will generally need at least one MonoBehaviour as an entrypoint
Eh, I'll just make a gameobject called main and put all my monobehaviours on there
Yeah could just get the focusedWindow Title Content Text if it's the game view or scene whichever is the use case.
Can anyone please help me figure out why my gun is moving downwards when I shoot?
Press Z to switch to Pivot mode
I bet the pivot of whatever object you're rotating is off center for the gun
you'll also want to show the actual code for the shooting though
because this recoil script looks like only half of the equation
It's just behind the gun
You want this generally on Pivot/Local
Ok show us the shooting code - where's the code that actually initiates the recoil movement
i.e. calls RecoilFire?
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 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.
https://paste.mod.gg/bgebygrjoxzd/0
This is the code that controls the recoil movement. I have a seperate code for shooting
A tool for sharing your source code with the world!
yes you showed this code already. Show the shooting code
also which object is selected here exactly? Looks like only a part of the gun?
How does the hierarchy of this gun and the thing holding it look?
Oh dude, my bad! I have a Gun parent object (which is empty) that has all the gun components inside of it. my shoot and recoil scripts are attached to that. It looks like the pivot is below the gun
https://paste.mod.gg/zpkxirfjlcmr/0
This is the script for the shooting although it doesn't do anything related to the recoil
A tool for sharing your source code with the world!
yeah so when you rotate around that pivot, the gun will appear to move down, no?
you can just move the object that has the renderer
the child object
to where you want it
I've moved it so that the pivot is near the grip, but the gun still moves downwards when shooting
make sure the pivot you're working with in the editor is the same one you're animating in code
(please don't crop screenshots, it removes helpful information)
The script is attached to the selected Gun object and in the script, what's affected is "Transform.rotation" so that would be the same pivot, right?
yes
change the rotation in the inspector a bit to see how that rotation will affect things
if it's doing something different than when you run the game - some other thing is happening
Hi, I'm trying to use yarnspinner for a dialogue system but I'm running into an issue after completing a build (either webgl or win64). Basically, the button to continue dialogue on click autodisables.
I'd appreciate any help. The issue is specifically triggered by building.
The docs say: https://docs.yarnspinner.dev/components/dialogue-view/line-presenter
"The supplied Line Presenter has an arrow button at the bottom. Clicking this will call RequestNextLine on the Dialogue Runner:"
Details:
- In Editor (fresh scene with default presenter from Dialogue System ), continue button works as expected: one can click and trigger "RequestNewLine" via default arrow button.
- After building for WebGL or Win64 development (no code changes as seen in git), returning to Play mode in Editor shows that the button is disabled and non-interactive in the inspector (see first image) even after the first line of text finishes appearing, and therefore, dialgoue doesn't continue to next line. This persists after closing the editor and reopening many times.
- Creating a new presenter fixes it, but issue returns after another build.
Setup:
- Default Unity Universal 2D template
- Yarn Spinner component added via Hierarchy -> Yarn Spinner -> Dialogue System
- No other canvas elements in view
- Unity 6000.0.55f1
Please help me understand why is the button disabling itself during runtime after it has well finished typing the line and what I should i do to recover the default behaviour.
The image below shows it is disabled (during runtime)
Here is the repo with the minimal sample: https://github.com/jmferreirab/YarnIssue (you need to trigger build to trigger the error, otherwise you won't see the bug).
Does your gun have an animator or something?
No, I wanted the recoil to be done physics only
I'm not familiar with that particular asset but almost certainly it's something in the asset doing that.
one thing that's weird to me is we don't see it in the camera t all.
And nowe I realized the gun is a child of the camera and the camera is moving
my guess is you have some kind of impulse listener on the camera or something
I added the repo (its like 1mb). If you feel like taking a look.
Or maybe you could possibly suggest a dialogue system that doesn't break like this on unity 6 based on your own experience. Sorry for the trouble. It's fine if not haha.
Thanks a bunch for your reply. I feel overwhelmed because it makes zero sense lol.
in fact what's this "CameraRecoil" thing?
I mean it's sometihng in Yarn itself
which I assume is not free, and I don't have
no, no, its free. You can add from Open UPM or github. The repo has that.
You can also get it from itchio and pay
Literally just need to clone the github project and unity will set itself up with the package.
Ah man, I figured out the issue. I'm coming back to this project after a few months and forgot I added recoil to the camera
Thank you @wintry quarry
Yuup seemed that way
yeah that was it , thank you and @slender nymph
one of the asset I installed was controlling the cursor without saying anything so I was veeery confused
The manifest.json takes care of that:
Hi! I'm new to Unity and I'm trying to use a Tetris Style Inventory System that someone else made available for download here:
https://github.com/DavidSouzaLD/InventoryTetris-Unity
I'm running into a couple of Null Reference Exceptions when I try to run the game, and I'm almost certain I set up everything correctly in the inspector.
I get the error immediately upon running the game, on line 157 of the Item Script.
When disabling the function in LateUpdate, the game runs until I click on an item to move, I then get another Null Reference Exception, this time at line 330 of the Inventory Script.
on line 157
...this script?
perhaps show your stacktrace
for me Item.cs is 166 lines? If its okay I can send a screenshot of my VS Studio or maybe send a link to what my formatting looks like
the info you give for the other error you mention isn't sufficient to say anything either. something's calling it with null is about it
then you're looking at a different version of the repo or a different repo
use !code to show it
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 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.
(also the S in VS stands for studio)
A tool for sharing your source code with the world!
rectTransform is null
When I shoot, a bullet is instatiated from the gun barrel and moves forward in whatever direction the gun is facing. Because of the slight distance in between the gun sights and barrel, if I aim at something, my bullet hits slightly below it, not at the actual target. Does anyone know how to mitigate this?
this is an extremely common issue in games
isn't it a thing IRL too
one common approach is to fire the bullet from the center of the camera instead.
Another approach is to fire a raycast from the center of the camera and then make a visual-oinoly bullet that goes to that point
there's no perfect answer - you need to think about what's a priority for your game
Hmmm okay, I'll give it a go. Thanks!
yes in fact the distance between the sights and the barrel on a gun is a whole thing which is why sights need calibration for different distances
(that plus bullet drop)
making the rect transform public and getting rid of the {get; set;} lets it show up in the inspector and I can assign it, thus fixing the issue. Although I'm confused why the item script cant access the rect transform on my item prefab, I'd think I wouldn't have to manually assign it.
As for the second null reference exception, what could I provide to help solve the issue?
why the item script cant access the rect transform on my item prefab
I'm sure it can but the code isn't making any attempt to do so right now
stack trace and code, not sure what second one you mean
He could also fire the bullet from the muzzle normally and align it so it moves towards the center of the screen instead of straight forward from the muzzle
right - but to do that you need to do a raycast from the center and find where it hits, then aim the bullet there
and you may still run into issues of the bullet hitting cover when your sights are peeking over cover in that case. Which is maybe fine since that can happen in real life too
it appears to be intended to be set here (or in this manner) https://github.com/DavidSouzaLD/InventoryTetris-Unity/blob/main/Scripts/Inventory.cs#L99
I don't like that pattern 🤮
yeah yikes
True, I don't think any of them will really be perfect especially when near other objects but I guess it depends on how realistic they want it to be
The second issue I have is a null reference exception I get on line 330 of the Inventory script.
yep there is no perfect answer. YOu just have to choose which tradeoffs you want to make
Im not sure what is null on 330
Is your script identical to the github repo for that one?
Because it was different for Item
maybe share your version
Okay, Ill share just in case
either way - a NRE is usually pretty easy to diagnose.
Identify all of the references that are being dereferenced in the line. For example if you see x.y, x is being dereferenced.
Then just put a breakpoint there or use Debug.Log to see which one of those references is null
then trace it back to where it should be set to see what's wrong
are these your own modifications?
A tool for sharing your source code with the world!
i'd recommend just.. not doing that and perhaps using wrappers or your own classes adapted/inspired by that code
you'll just confuse yourself and others by saying you're using the scripts provided in that repo when you aren't
Ok so the only reference on this line:
if (slotPosition.x + width > gridReference.gridSize.x || slotPosition.x < 0)
is gridReference
right so you should check the stack trace and see what's calling this and how it gets that reference
so you have to go a level deeper in the stack trace
is this the same place it takes me when i double click on the error? because it actually takes me to the Inventory Controller when i click on the error, or am I misunderstanding
can you show the full error?
when you select it, you should see the full text at the bottom of the console window
when you double click the error you get the location of the last stack frame, the very top of the stack trace
oh so i get what you meant by deeper now
NullReferenceException: Object reference not set to an instance of an object.
Inventory.ReachedBoundary (UnityEngine.Vector2Int slotPosition, InventoryGrid gridReference, System.Int32 width, System.Int32 height) (at Assets/Inventory/Scripts/Inventory.cs:330)
InventoryController.Update () (at Assets/Inventory/Scripts/InventoryController.cs:25)
so the code that's erroring is called from InventoryController.cs:25
is that modified?
so inventory.gridOnMouse isn't set
seems like it's supposed to be set here https://github.com/DavidSouzaLD/InventoryTetris-Unity/blob/main/Scripts/InventoryGrid.cs#L64
are you using the old or the new input system?
Im using the new input system
oh wait no that would be OnMouseX that has that issue..
not sure about IPointerEnterHandler...
Does prefixing a variable with a underscore vs not prefixig it with a underscore serve any puprose?
private InputAction _moveAction
// example
it's convention to mark the variable as private
no functional purpose in the compiler.
so what's the use case of private then?
do you think im better off using this code as almost like a reference and building my own inventory system from the ground up?
it's a vestige of an era where IDEs didn't exist, it made reading code easier since you didn't have to go back to check how the variable was declared
now we can just hover over the variable
it actually makes it private
that's the part that actually does something
(although not really because private is the default if you don't put any access modifier 😛 )
Public is the default I'm aassuming.
you assume wrong
well, if you don't like how it is at its base, then yes
like i said here #💻┃code-beginner message
I'm listening 🤔
members in C# are private by default, adding private just makes it explicit
both adding that and the underscore prefix are style choices
they don't have an effect, the only rule is to be consistent
private is still a style choice but it feels more functional than the underscore because it's analagous to other modifiers like public, internal etc that actually do things
so you don't have to prefix it with a unscore it's just prefrence.
I appreciate the input, I like the base functionality of whats shown and its the beginning of what id want in my game. So I think I'll try to make my own system that way I understand it in and out. Thank you for your help!
Hey, how i can make this script, work on a 3D space?
Vector2 direction = objetivo.position - transform.position;
float directionX = Mathf.Sign(direction.x);
mortemRb.linearVelocity = new Vector2(directionX * speed, mortemRb.linearVelocity.y);
change the 3 Vector2's into Vector3's
and maybe change the directionX to Z, or well whatever way is meant to be forward
well, thanks :3
and might change directionX to a Vector2 (x and z) if it's intended to be a horizontal direction
float directionX = Mathf.Sign(direction.x);
should be changed to a vector projection on the x/z plane
yeah was gonna say to do something similar but i wasn't sure what they were planning to do with it
Yes ProjectOnPlane with Vector3.up as the normal
Alright im modifying a RenderTexture inside a compute shader to output the height (0-1) value to my terrain.
when i do this :
heightMap[id.xy] = float4(x, y, 0, 1);
it displays a normal uv map (proving it works). seen in image 1
but when i do this:
heightMap[id.xy] = float4(height, height, height, 1);
it becomes very warped for some reason. (image 2)
here is the full code
https://paste.mod.gg/ptarneakknfz/0
A tool for sharing your source code with the world!
the noise itself and vertex displacement works perfectly fine so its not wrong data
im probably being slow but i have no clue whats wrong
just curious what's the value of height? and why is it used for the 3 values?
the height value is 0-1 and right now its xyz so it outputs a black to white gradient
for testing
soon ill only put it in red when i know it works
it SHOULD look something like this
i think your scaling is probably just weird
basically it looks like that image, just squished vertically
that's what i was thinking as well
doing height *= blendFactor; in a loop is probably part of it
it only does that once
in the uv image does it look wrong to you?
i thought the black part was far too small
break; doesn't stop the whole for loop
sure it does
onlt that one instance it continues after
you're thinking of continue;
when i set nosieScale to 1 (originally 3) this happens
first image is what the texture is vs what the actual thing is
seems i was :/
damn things confuse me too much
wht happens if you output the result of your perlin noise function directly
without the getHeight wrapper or any of the other stuff
same issue i tried that
oh i used the wrapped actually
one second
then there's an issue with your perlin noise
but it works fine on the vertices?
have you tried logging what height is when it's used here
heightMap[id.xy] = float4(height, height, height, 1);
I mean it's a shader, logging isn't really a thing
the texture outputs are the logs
im using the same height variable for the vertex displacement and the noise generates fine
fair but it would show in the inspector if it was public right?
sorry a property, i don't use shaders much
No... there is no inspector. Shader programs run in parallel on thousands of pixels at once
the noise works fine
i dont know why the texture isnt
i tried what you said about using just the perlin2d function though and it generates the same issue
If you replace getHeight with this temporarily:
float getHeight(float2 pos)
{
return sin(pos.x * 0.1) * cos(pos.y * 0.1) * 0.5 + 0.5;
}
What happens?
ive just changed the colors so appologies for that
im trying to cut a path into the terrain which is why im doing this nightmare
ive made it so it writes that part as green
so the green stuff at the bottom SHOULD be inside the path?
Guys, how do I create a clone of a class object?
Like an independant clone of the same class with the same values. I need it to simulate orbits
- Consider using a struct instead and then you get that behavior for free with =
- Create a copy constructor or a function to copy it.
- Make all the values serializable and use a serialization framework to copy it.
Oh thanks, I'm gonna try doing that
those are 3 different options, by the way
Alright
so what language does unity support that is good for beginners?
C#
👍
Tbh, idk if unity supports other languages than C# without some random plugin
Unity realistically only has one programming language
I know godot has more than 1 supported
did unreal support multiple then?
Idk, it uses c++ i think
Unreal used to support multiple
Unity used to support multiple
both of them now consolidated to one
alr then
C# is a bit better imo, it got foreach loops
say do any of u have some ideas for an game tht is similar to stardew walley in terms of features
Stardew Valley in space
features not idea
stardew valley in my backyard
drunk people around the world
so does c++
my idea is tht player is an forger and u can sell ur creations for money or save em and go to a dungeon for more loot
Wait what? 😭
beer and geting drunk could be a good idea tho
might be a dumb question but: how do you assert that you calculated ur normals correctly on terrain?
most languages do
another feature is tht later player can monopolyse some buildings for npc like entry fee or sth
I haven't used most languages, only python, lua, c++ and c#
And Kerboscript
but the syntax/name is different in every language
this is the wrong place to talk about game ideas
Eh, tbh who cares
i was thinking tht 1 minecraft mod has the feature when u drink u get dizzy and ull be teleported somewhere randomly
#💻┃unity-talk then?
lol
if its tht bad i can switch but ppl are active on here so i can get faster opinions yk
I remember playing this game Cinabunny. It’s like stardew but better purely because evryone is rabbits
for..: in c++, foreach..in in c#, for..: in java, for..of in js, for..in in python
whoops missed my own message..
what is with you and writting that as "tht"?
dw
yeah we'd much rather you ask in appropriate channels
somehow i managed to make ths channel talk about code language and stardew walley
u see im super lazy
average programmer
#💻┃unity-talk is fine then?
-# why is there no intellisense in discord smh
-# why are we talking in small letters now
"-#"
-#test
im smurt
There's no off-topic here. If you want to talk game design create a thread in #💻┃unity-talk
-# i like men
google exists yall
ur late lad
He's a mod
if its small question like how to make small text thn ion see the prob
it's unnecessary noise; again, google exists
also, copy text exists
you can literally just find out yourself in 1 second without having to ask anyone
takes longer tho
Next one will be muted
why is it 0.1 in unity and why setting acceleration to 1 or higher will make the character movement clanky? (i'm not smart enough to understand it)
I have a WeaponController firing an AttackOne Unity Event. If I understood it correctly, I have to drag the script with the function I want to trigger into the event field in the editor, but when I do that it doesn't show me the methods of that script. How do I define a method that can be triggered by that Unity Event?
it's 0.1 because that's what you set it to in the inspector
Also for sharing code don't use screenshots.
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 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.
currently all I see is this
you dragged the wrongf thing into the slot
you need to drag a GameObject that has the LiskarmAttackScript attached to it into that slot
not the script itself
public class Orbit
{
public List<Orbit_segment> orbit;
struct Orbit_segment
{
public Vector3 position;
public Vector3 velocity;
public float time;
}
}
Why is this wrong? Sorry for german warning btw, gonna change language later
doesn't the error tell you exactly why it's wrong
orbit is public, but part of its type is not
you can't have a public list of Orbit_segment since Orbit_segment is private
the struct has to be public too
is that not what the error says
Nah, not realy
It says less accessable, too cryptic for me tbh
well "access modifiers" are things like private public
so it's saying Orbit_segment is less accessible than orbit which is a problem
First or second time having this error, pretty new to c# and unity in general
gonna remember that
Dang, rewriting this entire physics script was the best decision I've made so far. I can literally just make a loop and calculate the orbit from that lol
Think of Private as like your bedroom and public as the front porch is how I've started to remember.
Oh, I think of it as local variables in lua
or indentation levels, like in python I thnk
Eh, works for me
Unrelated and unsolicited advice, but that struct would typically be either defined outside the class (and named OrbitSegment) or if it's inside the class it can just be called Segment (so that its full name is Orbit.Segment instead of Orbit.Orbit_segment)
that's one way, I'm new to the whole programming all together, no programming knowledge or computer science so tryna use real world examples with certain modifiers etc
scoping is about what you're thinking about at a given time
accessibility level is about what info you give to other people (or allow other people to change)
Gonna change that to segment, thanks
to generalize the above advice a bit - types are by convention always PascalCase
is a general question about events code talk or unity talk?
I used to do that in python, then i "read" the conventions and switched_to_this
that's gonna be a 😬 when you have a deep misunderstanding because you conflate those separate concepts
python's concept of access is very loose and unlike c# it's not enforced
pretty much without plugins / editors
eh, ask first and we'll go from there. it might relate to other things
Not that the admin is gonna come again and mute us
jesus christ stop whining
if I make a multiplayer game, and two players have events with the same name, will unity still keep them separate or will they trigger other people's listeners?
Yep. Underscores are meant to be private by convention and it's only enforced by static analysis tools.
What do you mean by events with the same name? In what context?
depends on how you trigger the event
What kind of events
if it's by name, then yeah i guess it would? but usually it shouldn't be by name, or at least not just by name
I think yes if they're local and not over the network or smth
never used events in unity
for example, my weapon controller fires an AttackOne event on button press, and then the attack script listens for that event and executes the attack. but I meant for the weapon controller to be general purpose and shared, so they all would fire the event with that name
What kind of event
And how is it listening
Unity Event
And is it a static event
Or an instance variable
Unity events are not fired or subscribed to by name
It will trigger whatever specific listeners you have added in the inspector or in code.
why don't you just try it
ah I see cool
because multiplayer functionality isnt implemented yet
in germany we say "trying > studying(like in university)"
If each player has their own weapon controller with its own listener, no the paths won't magically cross
usually it'd be by reference, like with delegates in this case
so the question then becomes - does everyone share the delegate, or does everyone have their own
also, if I then want to make an event that can be listened to by other players, I'd have to use a different kind of event right?
idk if it even makes sense to do that tbh
no, everyone gets the same game version with their own same events
You also need to tell us if this is a local or network multiplayer game
oh yeah that's true. If it's local you can run into problems
network, although maybe it could have local too
Not a different kind of event. Everyone just needs to reference the same event.
Networked no nothing of the sort will work
You need to think about RPCs for communication over the network
Or network variables
aside from explicitly networked things, there is no communication between clients in a networked game
I think it will probably be a p2p type game
only problem with local is if you do use a global event manager with two similar controllers, but not hard to not code yourself into that situation
regardless of the network topology, nothing goes over the network that isn't explicitly networked
:loudspeaker: Collaborating and Job Posting
We do not accept job or collab posts on Discord.
Please, use Discussions to promote yourself as job-seeking, advertise commercial job offers, or look for non-commercial projects to participate in:
• Collaboration & Jobs
i think they're here lmao
Trying out Unity's awaitables. For something like this, is there a return type or method I can use to exit out of this method that would remove the warning? Not every instance of this method needs an await, but some do
Unitask had a way, but can't seem to find the counterpart in this framework
you can return default as they dont have a static var like unitask does for a complete task
what's the warning, btw?
the warning will be that the function does not await so its synchronous
so you can remove the async keyword and return a task object instead
return default only works if I remove async from the signature
But problem there is that the method is being awaited on, and return default breaks it and it stops ther
its fine
Oh, then that means a new awaitable instance is not in a complete state
unitask is fine
What would the syntax for that be?
with uni task its:
public override UniTask Thing()
{
return UniTask.CompletedTask;
}
and we can see from the src its actually just a new UniTask instance
so unity fucked up somehow
I know for Unitask, I'm asking about Unity's awaitable framework
no idea they have nothing similar listed in their docs
you can try doing return new Awaitable() instead?
but if it gets awaited forever then its not going to fly
Unity plz fucking finish a feature
unitask is just better it has way more features making it a good Task replacement
genuinely curious, what is the point of having async function without awaiting anything or why does it matter if the warning stays ?
its when you are overriding something that returns a task
some things may need async some may not
oh soo it seems to just be a superficial thing not wanting the IDE warn about this function being run as Sync not Async
Hey got a question. Please ping me if you answer, but I know UnityAction is a delegate, but what is UnityAction<> for? For example, UnityAction<float, string>
yeah this is painful when doing Unity events like button you cant attach a Task method and you need to do async void which is not recommended but we have no choices for UI event callbacks usually
well yea but also better I think if you just return a task without async manually as it may simplify the compiled code
Yea unitask has helpers so you can avoid a () => MyAsyncThingy().Forget() (UniTask.UnityAction)
UnityAction is the same thing as System.Action except its running through unitys event system iirc
I know but I meant the values part, the <> parts
Because I saw that in Unity's FPS Microgame
I was just curious what those do
those are just the types you want to pass through the event
if you did Action<string> then a string is expected when you do Invoke
its the generic type argument that specifies the first event arg type
Okay, and just to clarify, UnityAction is the thing in the inspector that you can tie to a certain script or a gameobject, etc right?
no thats UnityEvent
yea, unity event uses the UnityAction delegate type
a delegate type is just a definition of a function signature
if this confuses you then you can research c# delegates and or c# Action
Huh, anyone have documentation on UnityAction I can read? I know the documentation page of it, but I wanna see further examples for how it's used
most times you should just use System.Action
It's just a plain delegate. It's identical to System.Action
UnityEvent if you need inspector . everything else stick to Action or your custom Delegate
public event Action myEvent 🙂 fast code event
public UnityEvent myUnityEvent; mid speed code event and slow inspector subscriptions 😐
public Action foobar; delegate abuse please seek help
UnityEvent. is really good when doing assets / modular
what is public UnityAction baz; in that case?
"oops we accidentally copied Action" /s
😐 what cursed thing have you brought upon this land
alright im gonna post this one last time before i completely give up even considering it for today
this is my compute shader
https://paste.mod.gg/rrymxsdcvpat/0
how would i go about adding a texture, in which i add the height value as a color? without causing this weird artifacting
A tool for sharing your source code with the world!
the "weird artifacting" is in the replied message
anyway with normal c# events the delegate type can be anything, UnityAction, Action, your own its all the same
its more of a code issue no?
well shader code normally went in #archived-shaders but I guess this is now #1390346776804069396
I see now. I just watched a video on it. For example, if you have UnityAction<float> when you invoke that action, you must insert a float value when you invoke it
dang guess i was teaching no one
its okay cause I made the same exact example instead of float used string but that kinda flew out the window ig lol
Oh I apologize, I didn't even see your message
yeah its just so basic though i think its all good here
i have absolutely not a clue why it wasnt working
hoping someone with more braincells than me can figure it out
If I knew shader code I'd chime in lolno idea sry hence why I think someone in that forum might have more xp
nah its all good
the data works and the texture coordinates work but put it together and it just doesnt
overriding it or something ?
dam UnityAction only gives you 4 Args ? fuckn amateurs..
https://docs.unity3d.com/ScriptReference/Events.UnityAction_4.html
Microsoft says 16 
https://learn.microsoft.com/en-us/dotnet/api/system.action-16?view=net-9.0
if you need 16 args in an action...something is wonky with your code or sum..
well you can define your own delegate type so its not really an issue (except with UnityEvent specifically)
just strange giving someone 16 args I wonder who requested that lol like just make struct bruh..
defining your own delegates is for wimps, in this household we use currying 💪
Action<T> is all we need
that's just what lambda calculus is, huh
what is the replacement of rb.drag, rb.linearDamping?
thanks :3
Did you manage to fix this?
If you're using Cinemachine 3 the new namespace is now Unity.Cinemachine
additionally - much of the API has changed, so it's likely things will have to change other than the using statement
But yeah the link boxfriend supplied above is relevant: https://docs.unity3d.com/Packages/com.unity.cinemachine@3.1/manual/CinemachineUpgradeFrom2.html
ty!
how do you change cursor on a button? do you just have a script chagne the cursor on every button ?
use event system raycast and see its hovering over a Button type if so switch out cursor
or use IpointerEnter
IPointerEnterHandler/IPointerExitHandler
so first one is update() on empty object and second its still script on everybutton?
Pointer events FTW!
is pointer event basically script on every button ?
I would write one script that allows you to assign textures for mouseover and just put that same script everywhere you need it
make heavy use of prefabs to simplify the authorship process
i dont know why my 3D character has a floaty jump, like if were on the moon
Just go to the rigidbody and increase the mass and gravity scale to your liking
increasing the mass makes it act weird, tho i didnt thought of the gravity, thanks
how i modify the gravity?
It should be in the rigidbody component no?
... no?
Oh mb but u can check the project settings by going to edit in the top
Also can u send me the script I wanna see how your jump works
that's only for the 2d rigidbody
but i mean, why this happens with default gravity?
wouldn't default gravity just well, make things fall, normally?
well, it's not gravity causing the issues but instead how you're handling your jump in the code
changing the gravity will definitely make it feel less floaty, will also make it so you dont jump as high though
I think u might have to use like the time.deltaTime thing
pretty sure most games like mario increase the fall speed artificially to make the jump feel less floaty. platformers are a surprisingly nuanced genre though so there's a range of different ways to fix it
wat
how do you move player , code wise
all is here https://paste.ofcode.org/YVDKfu6uhmDHCSXDmC4kiF
I don't have access to my computer rn but I think u can just look that up on the unity docs
deltaTime just manages frame dependency in your code. it wont affect how floaty the jump feels. jonas tyroller has a great video on deltaTime usage, if you want to learn more
why do you have this rb.AddForce(moveDirection.normalized * moveSpeed * 10f);
mixed with rb.linearVelocity = new Vector3(limitedVel.x, rb.linearVelocity.y, limitedVel.z);
First is for movement.
Second is to set a speed limit
for movement
I thought it was if you have a low frame rate it would just slow that game down and that might be the reason for the floaty jump but delta time fixes that
oh was looking at the wrong methodm
and make it dont go nuts
oh you mean movement2 and movement?
i was experimenting wich movement was better
as you can see, there's nothing that calls movement2
yea saw you had two my mistake
so i should just modify the gravity?
i mean cuz modifing the mass i think makes it slower :<
modifying mass has no effect on how it falls
Follow Isadora's Edge on Kickstarter: https://www.kickstarter.com/projects/inboundshovel/isadoras-edge
Wishlist Isadora's Edge on Steam: https://store.steampowered.com/app/3125320/Isadoras_Edge/
(My actual fast fall value is about 47.5% but that felt too wordy to use in the video)
The game that I'm developing an an indie game dev is called Isa...
#📖┃code-of-conduct no shit posting / offtopic
W h a t
yup, that's what i meant earlier ^^^
making the player fall faster lets the player do their next input faster. good for fast platforming if you want to give the player more time to react faster to obstacles.
How i do so?
famously so
ever heard of the hammer and feather experiment?
Does anyone know what a boocean is, it keeps popping up
boolean is a data type that is either true or false
it can only have two values, true or false
unless you actually meant "boocean", no idea what that is
No it says boocean
No
But i mean actually Doesnt matter rn
BooCean?
WHAT IS BOOCEAN
How i can do this?
Is that what pops up in your warning?
you're going to have to give us more than that
Wat
DID GET A VIRSU
How i can do the fall thing?
wdym " the fall thing " ?
Like in mario.
I dont know
I just want to fix my fall
Or i should just modify the gravity?
You'll need to explain the issue that you're trying to fix.
<@&502884371011731486> they're trolling, also not the first spam/troll message they sent (message that was deleted earlier and the japanese shitpost in #💻┃unity-talk which was also spammed but prompty deleted by dyno)
no one here is going to help via DMs. if you have a question or want to help, just use the correct channel
sounds like weird scam / phishing
I wanna work unity project, hdid?
The thing we were speaking before
The player when jumps falls very slowly
A way to fix it is modifing the whole game's gravity, but i feel like that might be too extreme
Assuming the objects size/scale is normal and you let physics control the object falling, it should be falling at the same speed/acceleration as in real life.
Games like Mario often have gravity increased
me and krish also posted a solution which should fix the floaty jumps.
should just be able to add some artificial gravity with something like this
if(rb.linearVelocity.y < 0)
rb.AddForce(Vector3.down * fallSpeed)
Define Normal
Then you're either interfering with physics or have some damping/drag settings
I didnt touched a thing on sizes if thats what you refer
I have some drag things in code
Tho
I use it for fox the sliperring
And when i set it to zero the fall keeps slow
normal is accelerating at ~9.81 m/s^2
minus air friction
Ah, you meqnt gravity. I meant objects size
Normal character size is like 2 units
which is roughly equivalent to 2 meters.
Anywhere in the range of 0.5-2 would be fine. Buf if it's scaled up to like 100s units, it would look like it's falling slower simple due to the scale
O h
i deleted the linearDump function, is the same
still falls slowly
You'll need to provide some more details.
For starters a video of the issue would help.
here
what i did wrong? i mean cuz, under my opinion, everything should be fine
Take a screenshot/video of the rb inspector during the fall/jump
here's the screenshot
And the drag is 0 all the way from starting the jump to landing on the ground?
yep
The falling speed seem about right I think.
but doesn't feel like is like too floaty? like if it were on the moon?
mmm idk, something tells me is slighty wrong
No. It seems to align. Check out this video. They're throwing a ball from 2 meters and it takes around .62 sec to fall down.
https://www.youtube.com/watch?v=6PiACgsutGw&ab_channel=PhysicsBurns(RaymondBurns)
Then look at the attached video where I drop a .1 scaled sphere(basically 10 cm diameter I think). It takes around the same time to fall from 2 units height. The same is true for the capsule.
O h
But i mean. Then how i should do for make it jump and fall faster?
As I said earlier, games like mario artifically increase the gravity constant.
Fall speed in mario is not realistic
So it's fine to adjust the gravity if your game requires it
Or you can add extra downwards force during the fall, just like @rich ice suggested.
yup, should be something like this
if(rb.linearVelocity.y < 0)
rb.AddForce(Vector3.down * fallSpeed)
may also want to check if the player is grounded, to account for slopes.
It might also be way simpler in mario. It might be a constant speed throughout the fall
In real time(and unity physics) objects are accelerating as they fall, so the initial fall speed is very small, but as the object continues to fall, it grows more and more
Many platformers would prefer a constant fall speed over the realistic model
Or ast least some modified form of it
and Unity has a realistic model for default, isnt?
Yep.
Well, it's a simulation, so it's not 100% realistic.
but is more realistic than a plataformer
But it's way closer to realism than what you have in many platformers
yeah
I hope this is the right place. Im making a 4x4x4 cube made of basic cube gameobjects, that are childed to an empty parent. Im trying to rotate the entire 4x4x4 cube around its center (0,0,0) and have it spin but whenever i mess with the rotation it ends up tilted and not rotating the way i want it to.
You'll have to show the code and explain more clearly what you want it to do and what it does now
do you mean tilted like this?
A tesseract?
i managed to get it to spin correctly on the x axis changing values cube vector offsets, parent's position, etc and now im 90% sure its the cube generation being wrong.(example of it spinning incorrectly)
change this to pivot
holy easy fix
would that also apply to "parent.transform.Rotate(Vector3.right, speed);" or would i need to specify pivot somehow?
transform.Rotate always uses the objects default pivot.
That setting only changes where the transform widget is shown in the editor. It has no other effect
that toggle was screwing up my testing, but i think im the right track now, ty fellas
Hi, can anyone help me? I'm trying to import a house model, but when I start the game, the camera gets stuck on the house. Does anyone know why this happens?
because the house probably has a camera
attached to it
in the top left search bar, type t:camera
it will show you all the cameras in the scene
where excuse me?
yes, you've got multiple cameras in your scene
hi, how would this go on a 3D plane?
protected void dispararBalas(GameObject balas, Transform balasPos, float bulletspeed, float angulo)
{
GameObject nuevoProyectil = Instantiate(balas, balasPos.position, Quaternion.identity);
Vector3 direccion = (objetivo.position - balasPos.position).normalized;
Rigidbody rb = nuevoProyectil.GetComponent<Rigidbody>();
Vector3 direccionAngulo = Quaternion.Euler(0, 0, angulo) * direccion;
if (rb != null)
{
rb.linearVelocity = direccionAngulo * bulletspeed;
}
}```
like this?
```cs
protected void dispararBalas(GameObject balas, Transform balasPos, float bulletspeed, float anguloHorizontal, float anguloVertical)
{
GameObject nuevoProyectil = Instantiate(balas, balasPos.position, Quaternion.identity);
Vector3 direccion = (objetivo.position - balasPos.position).normalized;
Rigidbody rb = nuevoProyectil.GetComponent<Rigidbody>();
// Apply horizontal rotation (yaw), then vertical rotation (pitch)
Quaternion rotacion = Quaternion.AngleAxis(anguloHorizontal, Vector3.up) *
Quaternion.AngleAxis(anguloVertical, Vector3.right);
Vector3 direccionAngulo = rotacion * direccion;
if (rb != null)
{
rb.linearVelocity = direccionAngulo * bulletspeed;
}
}```
why i am getting null reference exception when loading unity interstitial ads
that's not much info to go off of
this is the error and ad is not showing.
that sounds like perhaps you haven't set a reference as expected
what kind of reference because i have rechecked the adunit ids and can you explain please.
a serialized reference in the inspector
but this is a guess since i don't have all the info
you'd have to go check the line that's triggering the error, see which values are possibly null, and trace them back to where they should be defined or provided from
I have the issue with inconsistent jumping again, and although now it's way less blatant, on rare occasion the character jumps noticeably higher than it should. I added a bunch of code since the last time I had this issue so i'm not sure what the mistake is this time.
https://paste.ofcode.org/mzLQJwF4VnPXYAyPgd9Sjk
Also is there something I can use that's more precise than the Lerp function for decceleration ? because although the character stops moving when there is no input the velocity values never quite reach 0
This is a good article on how to use lerp correctly, it also goes through what to do for values never quite reaching the target value: https://gamedevbeginner.com/the-right-way-to-lerp-in-unity-with-examples/
Thanks for the info, i'll check it out
How do u guys spawn objects in a large 2D map? Everything in one go or only certain things that are going to be shown on the screen?
If it's large enough you almost certainly want to be doing world streaming (the latter)
You should start with everything at once though
See how that performs, then fix it if it doesn't
Wow thanks, I've been looking for the word for that technique
I'm only starting with a demo. It certainly can run without complex rendering
But I need to showcase my skills to the employers so I'm trying everything possible
why using method 2 makes my character able to do infinite jump (please explain like i'm a monkey i'm not smart enough 😭 🙏 )
https://paste.mod.gg/tepkjbgerzxu/0
A tool for sharing your source code with the world!
Because grounded will never become false with method 2
isGrounded stays true if u don't collide with anything else
You will always think you're grounded
so it wont update until i collide with other things?
Read your code. For grounded to become false you would need to collide with something that has a tag other than the grounded tag.
Is that happening? No. So it won't become false
That's why OnCollisionExit is needed
Code only does what you tell it to do
what's that?
Have you actually read your code? It's there in option 1
oh i didn't notice that
OnCollisionEnter only called when u collide. If u stay in the air, it's not called, no comparison is made, hence isGrounded keeps its last value unless u change it elsewhere in the code.
Can someone help me why my onmousedown doesn't work?
`using UnityEngine;
public class ClickOnBird : MonoBehaviour
{
void OnMouseDown()
{
Debug.Log("Hello");
}
}`
are you using old or new input system
I don't know, I am using the default one
default of which version? it recently changed
Which unity version
Input System Package (new), is this what I am looking for?
yeah that doesn't work with OnMouseX
(Google how to use that)
this, or switch input handling to the old one
i mean if they're following a tutorial it'd probably be better to go with what the tutorial's doing
just for now while you're using the tutorial
Well they're already using the wrong Unity version for that 😛
I'll try that, I am not following a tutorial, I wanted to try unity out because I've been learning c# on a basic level, like making databases in wpf and stuff, and I am trying to make like blackjack and stuff to learn
if thats the case IPointerDownHandler is what you want
for it to work you will also need to have the correct raycaster on your camera, is this for a UI object, a 2d object or a 3d object?
(also an event system)
I've got it working, added an event system and a raycaster on the camera, I am working with an empty thing that has a sprite renderer
I am probably making it harder for myself not using the UI system
I recently learned how to use "=>", and it seems a bit too good to be true. Is there any issue with using it like I did here?
that's just a read only property, it's nothing all that special
It does make it so I don't need to set "waveFinished" in a method though - I'm just wondering if there is any reason I shouldn't do that I guess
It’s typical to use a CapitalThere for properties like you would functions btw
oh yeah true
It's the same as a function that runs that expression every time
Nothing more than a shortcut
Note it's not storing anything
Nope, very common and very great. On more expensive conditionals you might prefer to cache it via setting a manual field
okay so let's say it was a more expensive conditional - it would make more sense to actually store it, and therefore we don't run the method every frame in update for example
right?
Potentially
If they're explicitly needing an up to date expression though, is fine.
It depends on the access pattern
Yeah but like don’t overthink how expensive we’re talking about here, you can spend a lot on dumb checks and iteration type stuff for properties like this
If you write a lot more than you read, then no sense caching.
If you read a lot more than you write, it can make sense to cache
okay so as a rule of thumb - if it will be called in update, I should probaby store the value normally
Not necessarily
Once per frame is still really slow and infrequent in computing terms
If you did it 40,000 times per frame, sure
I know, I just mean more broadly in terms of building habits
If it’s in update and doing multiple layers of iteration maybe
I'm prone to adopting something and paying the price later lol
I think it would be a mistake to make a variable for this particular thing as you're duplicating state
It's not significant to performance
You can get away with a lot here, these types of conditionals are crumbs compared to anything actually problematic
Just use whatever's readable for you and your team
oh yeah because I can just check whether spawnedEnemies.count == 0 directly
like SplineAnimate 😢
Yeah and this is just a shortcut to that
With a variable you risk them going out of sync
This is also powerful if you theoretically don’t care who wants to see if the wave is finished but don’t want strangers touching that list directly
Btw what on earth is up with SplineAnimate component? I recently made a game for a gamejam using Splines, and it straight up drops 170fps when running
It's private though so not applicable but yes
I am watching a video and see the person using constructors on MonoBehaviour derived classes. Is there really a need for that when you can just Initialize them on awake?
Not only is there not a need for that, you literally cannot
You should generally avoid using constructors with that, a method like Init(custom params) will work fine
Im looking to make a dialogue mechanic in my "Mostly UI stuff" game. Can someone recommend me a good youtube tutorial for creating dialogue, similar to how Papers Please dialogue works? If not, any dialogue tutorial can work
All right. Thanks
If you make your Init method return itself you can do the same as a constructor too :catye
Awh damn no custom emojis 😞
Yeah it got me confused a bit. I think they never use it themselves either. Just making Set methods afterwards...

These two dimensional arrays making me so confused too smh
Seems like a bad tutorial
Yeah I think.
I assume I need to get rid of this green leaf then 😡
I shall continue to cope, in that case..
Is there a way to hide thing in editor without inactivating them? I dont want to have to activate my fade panel everytime I go test and deactivate it when in editor so I can see stuff
Press H on the selected object to hide hierarchy things without actually turning them off.
Okay, so I'm kind of losing my mind here, or at least, it feels like I'm going crazy.
I need a way to deep clone a class without manually defining everything that will be cloned in it. Just- Clone every single thing, all the references get clones, everything.
And yet, as far as I've been able to find, this is just- seemingly impossible? The closest I've found is writing a class to JSON, then basically reversing that to get a new instance of the class, but that seems ridiculous and inefficient.
There are ways to clone Monobehaviors and Gameobjects, but I don't need those, I just need a normal, ordinary class, that holds references to normal, ordinary classes, ect ect, and a way to just clone the entire hierarchy from top to bottom.
so a Deep Copy?
why does my public list when reloading the scene become empty?
Yes. Pretty much exactly that.
either something is clearing it, or it isn't empty and just filled with missing objects because it's on a DDOL object and referencing things that were destroyed when the scene was
If you're modifying it while the scene is playing, or modifying it through a script running in the editor without marking it as dirty, the changes can get lost. There might be other causes, but that's usually what happens when my lists get messed up.
Whats causing it
oh okay, have you looked into how to perform a deep copy in c# ?
I have looked into it, but all the resources I've found basically say you need to manually implement every layer of the copying process, which is not really feasible, for my usecase.
(Context, if it's absolutely needed: I'm trying to clone "Equipment" in my game that has some pretty beefy hierarchys of references self contained within it, which would mean for a fully manual cloning method, I'd end up with an extremely high maintenance problem when trying to modify it at all. The Equipment itself is a normal class, not derived from Unity's Monobehavior or Object classes, currently)
Not to hit you with the stack overflow question but do you need to do it this way?
i still don't know why unity is deleting my list after refreshing the scene?
yeah its common to do it that way , are Serialize/JSON not feasable for you ? imo they're the most straight forward way
I mean a couple of things have been asked you did not answer , what types of objects are in the list? where is this list? etc.. you cannot assume we know everything about your setup
Audioclips, i am using a unity editor only feature to auto fill them in the editor
Do you even need to realy copy all of that?
then thats the first place to look into. Sounds like it might be refilling with blanks
It is absolutely needed, unfortunately. My game currently has a custom crafting mechanic, which means items need to be able to know their relationships with one another, and also be copied from template assets without decently nightmarish consequences.
I don't usually like clarifying what my usecase is, to avoid questions like this bogging down the solution.
if JSON works, I might have to use that, I suppose.
no it's on a context menu.
you said editor only feature to autofill ?
i just fixed it by moving something in the list and now it just works!
JSON / any serialization format will most definitely work
Custom crafting in like you can craft your own stuff, without you having to make the recepie?
I could be ignorant on this but this doesn’t necessarily sound like something the individual pieces have to own? Eg. This doesn’t need to be stored in a way thats nested if its owned by the surface layer
Spore Style crafting.
Items need to know their connected relationships, in order to spawn them from data during battles.
I have the system already functional, but there's issues with, like I said, cloning these hierarchies when needed.
this is basically a save system needed?
I think serialization / recreating it that way is the most straightforward
I have a save system, already, the hierarchy cloning is for editing safety, and certain Unity Editor functionalities, like accessing immutable templates to make copies of for various purposes.
But yes, I'll try serialization. Thank you very much.
cool! let us know how it works out 🙂
Uh, time to code my orbit visualization 😭
Would this work well to avoid diagonal movement being faster than vertical and horizontal movement ?
https://paste.ofcode.org/34MaU6WdfQV3jtp5a5rzgdN
Propably
for some reason setting it to just 1 didnt seem to change anything
but setting it to 1f or any other value works
yeah, vectors work with floats
This only works if the expected maximum velocity to each direction is 1
so should I set it to the maximum velocity for going forward since i dont want diagonal movement going over that ?
yes
Also,
is the way to go imo
Alright thanks, I was starting to loose my mind over this, gonna have to rework some of the code so it works with sprinting too
You already got the script, so change it and test it. Doesn't take very long, it takes longer to ask here I think
Usually you'd clamp the input, not the final velocity
Yeah dw i'm already workin on it
lemme try that actually
doesnt seem to work for some reason
ah yeah i get why now, my movement works a little differently, so i'll just stick to what i was gonna do
Oh,hello everyone,I'm newbie and my purpose when I joined group is hoping everyone support me.I extremely love AI🥰
hi, this isn't a social space btw https://nohello.net
if you have a question feel free to !ask
:thinking: Asking Questions
:mag: Search the internet for your question!
:book: Use the API Scripting Reference and User Manual and this troubleshooting site for commonly posted issues.
:wrench: Attempt to debug your issue.
:thought_balloon: Find an appropriate channel by reading the name and description in #🔎┃find-a-channel
:grey_question: And don't ask to ask, ask a full question illustrating with screenshots if needed.
-# For more posting guidelines, go to #🌱┃start-here
Oh okay i sorry , i don't know
guys how do u mark a whole scene as DontDestroyOnLoad?
DontDestroyOnLoad is per-gameobject, you would have to loop through root objects
Sup yall
So I need to clone a class with the following attributes:
public List<Physics_object> physics_objects;
public Physics_object center;
public const double gravitational_constant = 6.67430e-11;
Physics_object:
public Physics.body_type body_type = Physics.body_type.Planet;
public double mass = 1;
public Vector3 size = new(1, 1, 1);
public Vector3 position = new(0, 0, 0);
public Vector3 velocity = new(0, 0, 0);
public float sphere_of_influence = 100; // The range where vessels only get influenced by this body. Only planets have this attribute.
BUT: Physics_object is a monobehaviour. From what I've read, you can't copy them regularely, but you have to copy the whole gameobject it's parented to. How would I integrate it into this clone function?
public Physics_object Clone()
{
return new Physics_object
{
position = this.position,
velocity = this.velocity,
size = this.size,
mass = this.mass,
body_type = this.body_type,
sphere_of_influence = this.sphere_of_influence
};
}
but why not just make the entire scene persistent at that point
load other scenes additively
you want a deep clone?
Yes, I need one
Instantiate lets you clone gameobjects (or components - it'll clone the gameobject that the component belongs to) including all their components and children
that's what im trying to do
i want one presistent scene where i load important stuff once the game begins
then scenes per mode
like MainMenu, Level1 scenes
you can't use new on a MonoBehaviour-derived class and expect it to work, btw.
yeah, you don't use DDOL for that, you just load other scenes additively
I already saw that online, but should I then simply return the Instantiate(blablabla).GetComponent<Physics_object>() or smth
and then unload them as necessary
pretty much, though you'd be passing the Physics_object to Instantiate instead and getting the corresponding component back instead
though keep in mind - with this pretty naive approach, you'll be duplicating any objects that are referenced in separate places
Duplicate in the term of making new gameobjects in the scene?
is that initial class not a MonoBehaviour? if it is you might be able to just Instantiate that
i think the references should work if they're all children of that object
The class Physics is not a monobehaviour, no
if you have 2 separate references to the same object, you would end up with 2 cloned objects for each reference
Ohh, thanks
I hope that's not gonna become a problem
-# forshadowing maybe lol
Im looking to make a dialogue mechanic in my "Mostly UI stuff" game. Can someone recommend me a good youtube tutorial for creating dialogue, similar to how Papers Please dialogue works? If not, any dialogue tutorial can work
https://youtu.be/8oTYabhj248
You can propably use this and just abstract it to use it for you system. Google exists btw
Can someone help explain how async methods can react to events using delegates?
They can't? They can add subscriptions to events like any other code.
perhaps you mean a pattern like:
- subscribe to an event
- wait until the event gets fired
- continue```
it'd just be something like:
bool eventFired = false;
someEvent += () => eventFired = true;
// pseudocode
wait until eventFired == true```
Pretty much what I'm trying to do is use an async to make sure the correct animation state has been transitioned to while volume fades to silence.
Then when transitioning to another animation has finished, restore the volume back to normal
you either subsribe to the event and wait till your subscriber has run, or just keep polling the animation state until you see what you want to see
or you use an animation event to set a flag that you poll in the async
if you dont want to code that yourself I can recommend UniTasks WaitUntil for this, UniTask in general is a nice library for async stuff
Unless that library is to big for your scope 😄
I was trying to do it with UniTask yeah, just using GetCurrentAnimatorStateInfo().IsName()
Oh if you are using it anyway you can just use WaitUntil and check for your state that you are expecting
but yeah its just doing what PraetorBlue explained above, it just polls the state each frame 😄
Ah ok, thanks, it's only for this use case where if a progress bar fills, an event fires. Using that I want to transition with silencing the audio and transitioning to that animation.
Then after that transition back to normal audio, with a different animation then playing a different timeline.
My game's basically interactive cutscenes
are you using unity animations for that?
if so I'd like to quote
or you use an animation event [...]
-# PraetorBlue
Thats most likely the easier solution 😄
I am using the animator if that's what you're referring to?
yes, in animations you can place events that you can subscribe to
As in like the state machine where I'm just transitioning with SetTrigger()
Oh I wasn't using this at all, I was using the animator state machine, not this, my b.
yeah but the state machines contain animations
if you click on one of the states, the inspector shows the animation "file"
Is it ok if we could make this into a thread and I could tag you?
Sorry I'm just having trouble understanding
Hey, someone knows why is this working... backwards?
Why what's working backwords?
i mean, is shooting from it back
You haven't provided any example of what you are experiencing, im not even sure if you are in 2d or 3d and there is not code i could help with
Henlo, is anyone available? I need help with something basic ~
!ask
:thinking: Asking Questions
:mag: Search the internet for your question!
:book: Use the API Scripting Reference and User Manual and this troubleshooting site for commonly posted issues.
:wrench: Attempt to debug your issue.
:thought_balloon: Find an appropriate channel by reading the name and description in #🔎┃find-a-channel
:grey_question: And don't ask to ask, ask a full question illustrating with screenshots if needed.
-# For more posting guidelines, go to #🌱┃start-here
oh, my bad
this is a 3D test of an enemy, it should shoot a lot of lil balls towards the player... tho it shoots them in the oppositive direction
the humble negative operator 

Was about to paste the same just didn't have the link on me
sounds like your math is off, perhaps show that part of your !code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 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.
o o p s
i just realized i didnt replied to my code
again my bad
this makes sense why nobody understood
update
{
dispararBalas(bala, transform, firingSpeed, 0, 0);
}
protected void dispararBalas(GameObject balas, Transform balasPos, float bulletspeed, float anguloHorizontal, float anguloVertical)
{
GameObject nuevoProyectil = Instantiate(balas, balasPos.position, Quaternion.identity);
Vector3 direccion = (objetivo.position - balasPos.position).normalized;
Rigidbody rb = nuevoProyectil.GetComponent<Rigidbody>();
// Apply horizontal rotation (yaw), then vertical rotation (pitch)
Quaternion rotacion = Quaternion.AngleAxis(anguloHorizontal, Vector3.up) *
Quaternion.AngleAxis(anguloVertical, Vector3.right);
Vector3 direccionAngulo = rotacion * direccion;
if (rb != null)
{
rb.linearVelocity = direccionAngulo * bulletspeed;
}
}```
here's the code
(objetivo.position - balasPos.position)
have you tried negating this
or, well, swapping the operands
no
that direction is from balasPos to objetivo
Is the rotation part needed? Should a normalized Direction work for linearVocity?
Meaning for the Vector3 direccionAngulo
for make the bullets be slighty angled from the line between the enemy and the player
but in this case no
which is the enemy and which is the player
so you get the direction from the enemy to the player
and then you.. rotate that value away from the correct value
thats the idea
pretty sure it isn't
think about that for a sec
you're getting the direction, and then you change it so it's wrong?
and then you expect that direction to be accurate?
i mean,
mmm wait
i mean in 2D worker
my idea is to be like the shoot of a...shotgun?
with some spread?
yeah
Just make the rb.linearVelocity shot on the forward of the transform * speed and have the quaternion rotation when instantiated be the rotation
now i just realized that the bullets also dont move......
i had them with rigidbodies, so it pushed the enemy, a mere glitch i was gonna fix
when i did it, i discovered why the enemy was pushed, wasn't for the huge amount of spheres....was cuz they were spawning inside of it
uuurggghh
doesn't make sense, the code works on 2d i just tweak it
you know what, i will return it to 2D and see again how i can convert it to 3D, cuz i dont know what went wrong
{
GameObject nuevoProyectil = Instantiate(balas, balasPos.position, Quaternion.identity);
Vector3 direccion = (objetivo.position - balasPos.position).normalized;
Rigidbody rb = nuevoProyectil.GetComponent<Rigidbody>();
Vector3 direccionAngulo = Quaternion.Euler(0, 0, angulo) * direccion;
if (rb != null)
{
rb.linearVelocity = direccionAngulo * bulletspeed;
}
}```
here's the original working code
what's the point of angulo exactly?
spread
As i said just move the rigidbody off the transform.forward and set the rotation in the instantiate function so your offset doesn't affect the speed
but doesn't has a rigidbody, i mean it shouldn't have one
just a collisionbox
you could do Physics.IgnoreCollision between the bullet and the collider of the thing that's shooting it, if that's an issue.
Then why are you using rb.linearVelocity
habit
but wait
in theory then it has a rigidbody then
letme check the og proyect
i mean if you're doing that and there's no error, it definitely has an RB
i mean, it pushes the enemy back
I'm trying to make a freelook binding, but right now I can only get it to work as a toggle instead of having to hold middle mouse to use it, how can I fix that ? I know that using freelook.perfomed makes it that way, so i'm wondering if there's a different method, because putting the Action Type as value (which I do for action where you have to hold a key) doesn't give me the option to add Middle Mouse as a binding.
https://paste.ofcode.org/BG5Z6CsxuSvdz4vmPPZV3Y
yep it has an RB, no idea why tho
do this instead:
Damn thanks, didnt know about this. Only little problem is that it stops me from seeing the state of the bool in the inspector even if it's public, but apart from that it works perfectly, thanks.
right because there is no bool
this is a property, not a field
it's equivalent to just writing a function:
public bool IsCurrentlyPressed() {
return freelook.IsPressed();
}```
if someone got any time to help with a basic 2D project let me know please, I've been struggling for a while (it's related to the new Input System and it's genuinely confusing)
The inspector is really NOT a debugging tool, get used to using Debug.Log or an actual debugger for that.
Yeah sorry i'm still very knew so idk about all that, thanks for sharing some knowledge. Felt the same way when I learned about subscribing to an event
oops, thank
guys how do you make persistent displays (like hp bar, level text, etc) that keep working after transiting between scenes?
Use DDOL objects
should I make the whole canvas DDOL or only the specific objects with each display? If the second option, how would I make it stay inside the current canvas from the scene?
"current canvas from the scene" doesn't really mean anything
you would make a canvas that is DDOL and moves between scenes
But it really depends on the specifics of your game
ok got it
Most games would just spawn the UI again in the new scene, based on the game data
It really depends on the structure and flow of the game
i gotta remake the entire display system I've just made
I frickin hate this scenes system
why?
Can't you just turn it into a prefab?
or make it DDOL and put it into a bootstrap scene?
I've done such a mumbo jumbo with events and idk
how can ı make better colliders in 2d polygon collider cant move in record mode and box collider is so useless for some cases and hard to control multiple boxes is there a better way to do it?
Record mode?
I am getting confused, has anyone had this issue before?
I'm working on networked/replicated stuff. I'm spawning in an actor with BPs server side. I then attach the actor to a second parent actor server side. The reason is I want the parent actor to move around and the child to follow it. (Object on a vehicle) So far so good. Child follows parent around.
I then try to destroy the child after detatching it server side. This works on the host session but not on the client side of things. Child actor stays there. :\
The strange thing is if I don't attach the child, everything works just fine. Attaching it seems to be the cause of the failure to destroy the child.
in animation section
you can edit colliders without knowing the exact math positions
manually
#1390346492019212368 might be a better place to ask
but polygon collider dont work with that
Oh are you asking for a way to change a polygon collider during an animation? Such as a sword swing?
If this is for a sword swing attack or similar, colliders are simply not a good way to do it
can you explain more? newbie in unity sorry
it's often much more convenient to use direct physics queries
i.e. OverlapXXX or XXXCast queries
i already built with colliders and it will hard to change i think
ı just wonder if ı can move multiple colliders in record mode or can ı move the polygon collider as ı wish
Rotation issue help
@final trellis Don't make people debug generated code for you.
Lookup a tutorial and test the code yourself.
less of a debug more of a "is it really doing what i asked" but fair enough
"is it really doing what I asked" is a pretty apt description of debugging
More like an apt description of generating code as a whole..
The answer is usually no
I need some help. I new to unity and I’m making a fishing game. I’m using a line renderer for the casting line but no matter what I do it’s behind everything.
The only case I got it working was when I changed the Z offset but then it was ahead of my player.
what are the things it's behind made of?
(MeshRenderers? SpriteRenderers? UI Elements?)
My game is pretty bare bones right now and it’s just a circle.
So sprite renderers
you need to use the 2D layer sorting stuff then. Check your Sorting Layers and Order in Layer for the sprie renderers and your linerenderer
This is a #1390346776804069396 or #🖼️┃2d-tools question btw, nothing to do with code.
Alright thanks, I’m already using layers
having a large long transparent thing is asking for trouble (due to how transparent objects do depth sorting)
but dont ask about it more here
https://paste.ofcode.org/mfqmHAVEbmUCAMthCTjDLh
I’m working on a UI upgrade system in Unity where clicking a “Buy” button should open a PreviewPanel showing details of the selected upgrade. The button click is registering (Debug.Log works), and the Show() method on my OrderedPreviewPanel script runs, but nothing visibly changes in the game view. If I manually enable the PreviewPanel in the Hierarchy during play mode, it appears fine, so the problem seems to be that my script isn’t making it show properly. I tried to use a different method named ShowRaw and assigned it to my buy button, but the panel is still not showing up. Any idea as to why it's not showing up? Chatgpt gave me some solutions but none of them worked.
do you have other scripts changing the active state? or Hide() called somewhere else
I can check in like 20-30 minutes. I’m not home right now. Is that fine?
hide isnt being called anywhere else and none of my other scripts are doing anything to the panel
is it something in the actual hierarchy or somethign
wdym by that ? also did check the heirarchy itself in playmode to see what happens
it gets disabled on awake cuz of that line in the script
and when i press the button the panel si still disabled
mb i mean like is it something to do with how i setup the panel
the script looks fine i think
I want a specific variable type but don’t remember it’s name
Basically it acts as a list but for each spot can store a few things like a variable and a game object.
Dictionary?
how do I exit out of whatever this is?
Every time I click on something it just gives me something like this.
I think im gonna reinstall this version
I have so much errors
debug mode is on in the inspector
what about the errors
TypeLoadException: Could not load type 'UnityEngine.Timeline.AnimationTrack' from assembly 'UnityEngine.Timeline, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
System.Reflection.MonoMethodInfo.GetMethodInfo (IntPtr handle) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:59)
System.Reflection.MonoMethodInfo.GetAttributes (IntPtr handle) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:75)
System.Reflection.MonoMethod.get_Attributes () (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:245)
System.Reflection.MethodBase.get_IsSpecialName () (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:184)
UnityEditor.Build.BuildPipelineInterfaces.InitializeBuildCallbacks (BuildCallbacks findFlags) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/BuildPipelineInterfaces.cs:191)
its whatever anyway im reinstalling
that not sure about , is brand new project ?
no its a decompile of something but it didnt do this before so I mustve done something accidentally
We can’t help with decompilation of other peoples projects
I'm not going to edit it and claim it as my own I just need some textures from it.
We still can’t help
Who are you referring to as we. Just wondering.