#💻┃code-beginner
1 messages · Page 707 of 1
yea
oh
at runtime its just a copy made with the prefab data and thats it
are you able to use strings?
oh
i assume it has to be Keycode.D
if i complied it would it work?
no
what should i do then
You need to take a different approach where you inform all spawned copies of this change or they listen to an event to respond to a change
e.g. keep all spawned copies in a List and when you change this "glow level" you refresh them all
if i wanted to check if"transform.GetChild(number) == null" how would i do that without transform out of bound errors?
Check if your number is not greater than the number of children for that transform . . .
i created a list with 6 elements so im changing each one individually now, but i cant reference child prefabs
what do you mean by "child prefab"?
the glow objects
those are child game objects
ah
you can use a serialized list to reference them
[SerializeField]
List<MyScript> glowObjects;
^ yep. You will see the list in the inspector and you can drag in your child game objects to assign them
very beginner stuff
it wont let me
wont let me drag the light object to the element in the list
What object has the list and which objects are you trying to drag in
And what type is that list
Okay, which object has the variable on it? These glowX objects are in a prefab, is that script also on the same prefab?
i need to attach this script to the prefab as well?
its also attached to a canvas to access a togglebox
that should work 🤔
unless there is another type in your project named "Light"
From the structure you've shown, you'd want target to contain a list of glow objects, so that when you spawn in a clone of target it would have a reference to its list of glow objects
ok
Scene objects can't directly access children of a prefab, only the root-level prefab object
wont let me drag the light object into the list even tho its attached to the prefab
im doing this from the project window
coudl that be why?
are you trying to drag scene objects into the slots on the prefab?
If the script with the list is on "target" and everything is within the same prefab it should work
not scene objects
object from a prefab folder i made
isLight from UnityEngine ?
yes
if they are part of the same prefab then most likely you are just using the wrong Light type in your code
do i have to speficy if its spot light or smth?
no
Do you have a script in your project named Light?
Right click on Light Go to Definition on Light see where it takes you
no, check the fully qualified name of the Light type you are using. you should be able to hover over it and see what namespace it's from
Can you show a screenshot of your unity window with this inspector visible? In the prefab edit mode?
okay, now click the little lightbulb (?) button on the Light component and see what namespace that one is in
it says light is from Unity.Engine
still think you're probably dragging scene components onto a prefab or somethin
u mean this
then you are doing something wrong when trying to assign the objects.
might be the other way round
can i not do that?
Is this from a prefab you opened up to edit?
yes
Scene objects you can put prefabs just fine
you can drag prefabs into scene objects. you cannot drag scene objects into prefabs. which is why i specifically asked you if that was what you were doing before and you said you were not
i did?
mb
im trying to drag these into a scene object
thats not allowed?
if the object is not on the scene
Which thing has the list you're trying to drag into?
you can drag the root object of a prefab into any other object. child objects can only be referenced within the prefab itself
As I said, it should be on the target object
canvas
im tryna make a toggle box that enables the target to glow when checked
it didnt really work
can you like show a vid what you did maybe ?
so i can add a gameobject constructor, then reference the child objects from there?
when using a spherecast for groundcheck, should the starting point be the player origin, or the origin + (vector3.up * spherecast) radius?
Gemini is insisting it's more reliable to have it be a radius above the origin, but the reasoning provided is contradictory

You would make a script on target that holds a reference to all of its Lights. Then you would keep around the reference to that target you spawn in, and use that to access its Lights
"ai"crapbot spitting contradictions... shocker..
yeah yeah yeah
so i need a seperate script that holds a reference to all my glow objects, then i access that script in my toggleGlow script?
depends on the usecase, there is no set way to do this, but its common to either make a separate transform for the origin of cast or use an Offset (origin + offset)
the origin being in the middle it means you have the make the cast longer , not much changes. As long as you put the Layers to ignore its own player caster, should be fine
offset upwards?
depends what you're checking, for a ceiling check sure, for ground check down
huh alright
Why sphere cast though and not overlap
is that because its less expensive to have the spherecast travel less distance?
maybe they need the RaycastHit info
oh yeah true
is overlap a physics method?
not really, would not make much difference
think you can still get some point of intersection
but yeah a raycasthit would be useful for determining the floor type
most cases Overlap is fine, if you need the hitInfo like slope angles and shite, use casts
then whats the advantage to starting the spherecast lower, instead of at player origin?
tbh thats not something I pondered much.. lol it would not matter as long you use proper distance / layer ignoring
It just makes sense to me to put it at the feet if its a ground check etc.
especially if you make the ground check slightly bigger than the player capsule you don't want his "hips" to count as grounded if the check spills outside
ok yeah that makes sense
for rays normally that doesnt matter cause they are a line, no radius
isnt it recommended to make the radius slightly lower than player width tho?
no it depends on the situation and how you are checking things, there is no set way to do it
sometimes the capsule has its corners hit a ledge, if check is smaller than the radius of capusle, its like stuck in place while the grounded check says "not grounded"
I usually make the groundcheck sphere like 1-2 cm bigger than quarter half of the capsule
@native flame
nea project?
i got in the new input system the event that when you click on attack, i also have when you get close to an npc you can press Z and gamble, opens a canvas with some gambling UI things, but when you press Z to gamble and then try to click in one of the things it attacks and disables back again the canvas, how can i fix this
disable the attacking / movement scripts while the UI is up
thanks yeah true didnt think abt that
use EventSystem.current.IsPointerOverGameObject()
not a reliable way to do it tbh
so thats a spherecast being shot from the feet with infinite distance, and if the hit.distance is low enough then grounded = true?
ill check it out ty
oh i guess its only useful for disabling clicks thru UI or?
then i guess it would be better to do a MenuActive bool that disables actions
You dont need to, you already have some design where the canvas will open up. Just toggle the correct input action maps at the same time
nah this case i used a overlap cause i didnt need much info from ground here so its just a simple "if hits something is grounded"
it says in the code the intensity changes but the prefab does not change at all
you probably wouldn't want to modify the prefab?
you'd be modifying a copy/clone/instance of the prefab instead
sidenotes:
- not sure you should be using
PlayerPrefsfor this - or at all, since it's not really being utilized as anything other than a variable - this is a "set" method, not a toggle
the toggle is in another scene
no, this just functionally isn't a toggle
a toggle would be like this:
bool state;
void Toggle() {
state = !state;
}
```what you have is more like this```cs
bool state;
void SetState(bool x) {
state = x;
}
to be clear - the note about the toggle is just a naming thing, it's not really a logical issue
i see
are you talking about my script being a toggle?
It's not toggle boxes, it's getting an understanding of how references work
im studying a level computer science so my knowledge is somewhat limited
I know this sounds dumb, but ive been struggling to get unity to recognize if the player is pressing R for the past 20 minutes. Im current using Input.GetKeyDown(KeyCode.R). I am so confused on why it isnt working
Remember - the prefab itself is simply a template. You copy the template and create a whole new thing. That thing has no connection back to the prefab, and the prefab has no connection to the things it makes. You'll want your toggle box to know which target you want to modify
Are there any errors in the console?
probably because Input system is defaulted to new Input system not the Old one
i was using he prefab as more of an efficiency thing
There are no errors for the script im using
does that mean for every target in my scene i would have to alter those?
in the unity Console Window , not the script itself
what would be the syntax for the new input system?
There are for some other script.
well. normally you would use the Action map.
but a direct translation would be Keyboard.current.rKey.wasPressedThisFrame
But none relating to what im trying to do now
i think im gonna forget the whole toggle thing for now, it was kind of a last minute addition to my program i thought would be fun and simple to implement
show the console window, AFTER you press R Key in playmode
maybe after a few prototypes ill come back to this
(wouldn't it error each frame it's checked anyways, regardless of if it's pressed)
nvm I finally got it to work
so what was it...
Kinda embarrassing, but basically I was using the invoke method after I detect R, and basically I messed up the Invoke method
I put Invoke("Reload()") instead of Invoke("Reload")
Invoke(nameof(Reaload))
strings are ugly and error prone anyway
yeah
you should learn Coroutines if you want to make delayed functions, they offer more benefits
Invoke works for the simpler stuff such as reloading a gun
but is very fragile and not very maintainable
coroutines are way easier to work with and keep track of tbh
if(reloading) return
StartCoroutine(Reload())
IEnumerator Reload(){
reloading = true
yield return new WaitForSeconds(reloadTime);
//Reload weapon()
reloading = false```
whats so difficult about that
even with Invoke, you'd need all the same pieces, just arranged differently
You see, you'd think that, but Invokes actually introduce a whole second kind of complexity that's much worse
So, Invoke is kind of a "noob trap"
It's more intuitive, but also more incorrect, so while it feels simpler to learn it's going to clip your wings in the long run. (similar to the old Input Manager vs new Input System but that one's mostly because decades of Unity tutorials were written for it and there's not enough new stuff to override that yet)
Ok Ill keep that in mind for the future
very true.
ontop of everything else
- you cannot pass arguments to Invoke
- you cannot stop specific Invokes , especially ones that repeat
I added a Box Collider 2D to an object, but I can't see the collider in the editor so I can't change it. Is there any way to move it or draw a new one?
did you turn on Gizmos?
also not really a coding question
yeah I did. Where should I ask then?
ok ty
How would I be able to use a variable in a different script than the one it's declared in
Reference that object and get the variable from it
Choose the best way to reference other variables.
does anyone know how to run the debugger through unity? i have breakpoints but when i run my code, it doesn't stop at the breakpoint
im not sure if this is what you mean but theres a small debug button on the bottom right of the unity project screen usually
this icon
does anyone know how could i make the npc freeze or at least not move once they die?
disable the movement script?
the npc only as a state machine
wdym as a statemachine
im in a programing class and the prof just gaves us a statemachine code he did and told us to use that one
you're just given random code without any clue on what its doing, what is the point of the class
xd no clue i got to take it its univeristy
i dont like this prof
he doesnt explain much
anything tbh
Presumably you would create a dead state and figure out how to transition to it.
well you have to make the script that moves it, not do that
i have no idea what im talking about and this should probably be disregarded because its inefficient but what if you save the location of the enemy at death and jsut keep it there
tossing them into FSM without any explanations how the system works or how to extend it , is just oversight of this "professor"
the first one i had was very good
but this one now he just throws us code without explaining
also a radar script that he did and didnt explain it to us
i made my own with youtube but this class its mostly the prof telling us what to do giving us code and we doing a different version yourself
so is the "Freezing" it into place part of the curriculum or , what is the objective
we are making a medieval game and he wants some guards that you have to kill
i made the health system with an observer pattern and once the health is 0 they play the dying animation but they still follow the waypoints that i made for them to follow
so i got no clue just to make them freeze
make a new state to transition into when that event occurs or disable whatever the movement into waypoints script is
tysm! this worked :D :D
yeah okay will work on that thank you
You could potentially destroy the entire object and then create a death copy at the position.. but thats pretty cumbersome even if its easier on the surface
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
anybody know why this code doesnt work when the program is complied
depends...how did you verify the script is even running
runtime
also next time post code with links not screenshots
What calls changeColour
changed colour to cyan and all my targets were cyan
a dropdown
Have you confirmed that the function is running
it does change the material colour
So... then it's working?
so then whats "not working"
this is such a roundabout way to map values
put logs and check the PlayerLog files / make a Dev build
you wouldn't be here if it worked. this does not give us any useful information to try to help you
ive told you all i can
during runtime, it works perfectly fine
but after i build & run it doesnt change the colour
the actual dropdown stays constant
Debug it
so does the dropdown actually click and show options? in build
YES
do i need to sned avideo explaining the situation
ok
fine
okay but really you should be learning debugging it, starting with logs in changeColor to see if thats even running in build
ive done those
ill send a vid rq
here
i dont get why this happens
done some googling and will i have to use a different render pipeline?
no
whats the issue then
how would I know if you don't debug it lol
ok you want me to debug.log and see what the output colour is?
log everything you can, narrow down to issue
check the Player logs / Devbuild console to see it specific to a build
where do i find those
check PlayerLogs link is in !logs 👇
check the "Development Build" checkbox in Build page
also you can check what playerprefs is storing value at
- Windows: Computer\HKEY_CURRENT_USER\Software\ExampleCompanyName\ExampleProductName in the Registry Editor.
https://docs.unity3d.com/6000.1/Documentation/ScriptReference/PlayerPrefs.html
editor and build don't share the same value/location *onwindows
Hey there,
How do I paint a terrain at runtime?
I generate a Maze for my Project on Start. This Maze has different Biomes. In order to detect what Biome is where I have a render texture that is generated after the maze by a orthographic camera. It outputs a 256x256 RGB Texture that is colored differently for each biome.
Now I want my terrain to use a Sand texture wherever the Sand Biome is (color red on render texture), a grass texture where the grass biome (color green on render texture) is and so on. How do I do that in a way that doesnt break my performance? I dont need it to change after the generation as the maze doesnt change after that
I believe you need something like this https://docs.unity3d.com/ScriptReference/TerrainData.SetAlphamaps.html
Hello iam trying to detect when object hits wall, tried using raycast acording to unity documentations but it doesnt want to work
thats from unity documents
Debug.Log = "touched wall"
This is nonsense
Configure your !ide so you don't make these mistakes in the future
you scoped hit inside a if statement
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
• :question: Other/None
yes use an ide compatible with unity out of the box like VS
auto mode lmao
This is why you look at the lines the errors are on and actually look at them to see if they make sense
yeah but thats how unity documentations said to do?
No they didn't
if(boolHere)
{
int myNumber = 40;
}
myNumber = 20; //errors because myNumber is scoped in the if block
they used hit inside if here?
hit is scoped inside the entire FixedUpdate method
yours is not
yours is inside the if statement block you did
hit only exists in if(right) block
just basic c# mistake, make sure you do beginners c# course before doing unity
doesnt help that you're using vim rn
your formatting is all over the place
used vscode with autoformating most of time before
mhm well put it to use then.
Some places you have K&R and some place you have allman lol
make sure the IDE is properly configred to work with unity so you also get proper syntax error highlight and intellisense
That works. Thanks!
They used hit inside the if it was created in.
Variables exist until they hit the next } and which point they cease to be

hey does anyone have an updated guide on how to grab inputs and move 3d stuff in unity?
cuz like I figured out how to take 2d inputs but 3d stuff seems to be more complicated?
should be the same thing... just switch Y for z
!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/lwqumanhlpjj/0 I'm making a block breaker kind of game, and I've ran into the issue that when the ball moves too slow, it starts hugging the wall upon collision instead of actually bouncing off. This seems to be an issue only when the speed is too low - the obvious fix is to increase the ball speed, but that's a bad solution design-wise so I'm wondering if anyone knows of a better method?
A tool for sharing your source code with the world!
oh yeah you're right
your chatbot is making you do custom physics while also applying physics materials that wont do squat
I would not use bounce material anyway.. rely on reflect, I would debug.log inVelocity and make sure you're not reflecting the velocity AFTER the speed got reduced hitting wall
oh yeah that sounds plausible
yeah honestly I barely understand the physics system, I really should learn it properly
ya log should tell you.
you can record the velocity in a variable then use that when reflect, or you should be able to also get it from https://docs.unity3d.com/ScriptReference/Collision2D-relativeVelocity.html
that fixed it!
thanks!
Input is completely the same. Moving things is also the same, just with 3 dimensions instead of 2.
i have a dumb question, HOW do u guys test your online game? Every other engine i used just opens 2 windows. How do i join myself?
-no laptop
so i have a class called CC_Spell, which contains an instance of the class CC_Spell_Range, which can either contain the normal CC_Spell_Range class or the CC_Spell_Range_AOE class ( which inherits CC_Spell_Range )
when i utilize JsonUtility.ToJson(CC_SPELL_INSTANCE); to turn it into a JSON string, will that disambiguation of which class it is be represented? if not, how would i? or is this type of data structure not supported by JSON
No idea if this is still the go-to but I've used this in the past:
https://github.com/VeriorPies/ParrelSync
unity 6+ has a good package for netcode
https://docs.unity3d.com/Packages/com.unity.multiplayer.playmode@1.6/manual/index.html
oh well what's with the character controller thing that a lot of tutorials use?
Is [Min(0)] public float MinIdleTime; essentially saying that whatever the value MinIdleTime is, it wont ever be lower than 0?
If so, why not use this instead of creating a separate static variable to compare MinIdleTime to?
it's not what I used for my 2d demo which is the main thing that confuses me
minattribute only covers the inspector..
but if thats ur use-case its enough
that for example wouldn't affect a runtime set variable
for runtime safe-guards u'd probably still wnat to use a property or clamping logic
for a chacter controller ur still usually only using 2 axis of inputs
WS-AD , arrow keys, joysticks etc
Horizontal and Vertical.. (for a 3d space w/ a cc normally the Horizontal controls the Y movement (left right) Vertical controls the X movement (forward and backwards)
and then for the third axis Z its normally controlled with a mix of gravity logic and for example the spacebar key (for adding force on the Z axis (up and down)
float horizontalInput = Input.GetAxisRaw("Horizontal");
float verticalInput = Input.GetAxisRaw("Vertical");
Vector3 input = new Vector3(horizontalInput, 0, verticalInput);
moveDirection = input * moveSpeed;
controller.Move(moveDirection * Time.deltaTime);```
super simple example ^ without normalization or local -> world conversions
Does anyone have any clue as to why my EnemyBody is avoiding the player in my "Roll a ball" project? I was wondering if it was the code but I even went as far as to copy and paste the entire code from the tutorial page into my PlayerController.cs script and it still happens and there's no mention of this issue on the tutorial page...
Free tutorials, courses, and guided pathways for mastering real-time 3D development skills to make video games, VR, AR, and more.
from "Step 7: Set the win and lose conditions"
first glance it looks like an offset problem
like the EnemyBody is offset from teh actual object thats rotating
and the Enemy gameobject appears to be rotating relative to the player
but since the enemybody is offset looks like that
you don't have to use it if you don't want. It's just Unity's wrapper around this: https://docs.nvidia.com/gameworks/content/gameworkslibrary/physx/guide/Manual/CharacterControllers.html
there's nothing stopping you from making a controller similar to your 2D one
It was, thank you! I moved the EnemyBody so the game wouldn't start with the enemy on top of the player and instantly lose from colliding on game start but I didn't realise I had to move the Enemy gameobject too, I just reset both their positions and then moved them both together to the side so the game could start and now it's working
np. make sure u stay in pivot mode
to see where the actual transform is
and you can move the root gameobject and the child will follow..
no need to select them all.. just remember tho its better to select a gameobject in the hiearchy to make sure ur getting the correct gameobject.. when u click into the scene its most likely gonna select the mesh or collider (thats probably farther down the gameobjects hiearchy) 👍
i made that mistake 100s of times when i first started.. and sometimes still do 😬 lol
i'll also use those little icons for the gameobjects while building things that are in pieces..
can help grab ur attention alot quicker.. than after u moved on to coding something else.. and then realize something isnt right 😅
hello, i´m making a 2D puzzle game where the player slides around the map, i´m using addForce to move them around, i´d like for the player to snap in the middle of tiles when it stops moving but i can´t make it work, i´m using the code below, also "rb.velocity = Vector2.zero;" isn´t stopping the player
private void FixedUpdate()
{
if (rb.velocity.magnitude < 0.05f)
{
transform.position = new Vector2(Mathf.Round(pos.x - 0.5f) + 0.5f, Mathf.Round(pos.y - 0.5f) + 0.5f);
rb.velocity = Vector2.zero;
}
}
If you're planning on doing movement by snapping to a grid you probably don't want to be using forces or velocity
You probably wouldn't even be using Rigidbodies, but if you do it'll probably be Rigidbody.MovePosition
aren´t rigidbodies important to make stuff collide?
If everything is grid-based you probably don't even need to detect collisions, you just need to know what object is in the space you're trying to move to
But even if you do want physics-based collisions you probably don't need velocity or forces
Those are important for making a realistic movement system but you're already not being realistic if you're doing grid-based movement
here´s what it looks like
just a playtest level
also i noticed a long while back that the player triggers scripts when the spites touch and not when the colliders though, the player is supposed to be slightly inside the portal (though i´d prefer it if was completely inside) but it gets teleported as soon as the sprites touch instead, same goes for a switch i made, the scripts work but visually it´s annoying
is this because of the rigidbodies?
do someone has experience in visual novel game ? (creating)
yeah but optimised 
i mean... how optimized do you need a visual novel to be lmfao
its just swaping around pngs and displaying text
i never made one tho so i cant say im 100% sure
but it sounds like you can just use unity and inky to make that type of game
yeah but the problem is how to make the swap sprite 
i mean you can probably find a video on that
i assume your new to unity? if so you should probably watch a video on unity basic
spriteRenderer.sprite = differentSprite;
hmm maybe new or not ? it surely my architecture too complex for myself lmao
thx
i have something i want to happen only once a state has changed: for example while a player might get a new quest while in dialogue, i don't want the "new quest" notification to play until the player is out of dialogue; how do i store the notification to make it wait until dialogue is over and then play?
maybe you could store the notification in a queue. once the dialogue is finished you could set a bool, something like "NotificationDisplayable" or something, to true after an event which could be invoked after the dialogue finishes
most simple would be boolean imo
canShowQuest = false;
once dialog finished set true;
once true -> show quest -> set back to false (awaiting next time)
but yea not jordan is onto something
problem with that is how do i store the quest notif? because if it tries to play and can't it'll just be done with it
will look into queues thank youu
i managed to make it work
had some code that looped the addforce
well ur system would store it and await for when it can be shown
Don’t throw the quest away if you can’t show it
Just store it somehow (in pendingQuest for example) until you can
Or queue them all if needed
storing it would be the simple part.. store it however u wish.. (in a variable i suppose)
public class Quest
{
public string title;
public string description;
public int rewardXP;
public bool isCompleted;
}
``` as an example
then its just a variable
`Quest pendingQuest = questGivenByDialogPossibly;`
i've not made a quest system just yet.. but i would think something like that naturally.. now i need to make one 😅
imo the harder part of quest systems is checking when the quest isCompleted
Ah yes the logic for quest conditions
I did something recently to let me have semi configurable conditions based on value comparisons
was it fun? sounds really fun lol
simple value comparisons would be about the only quest validation i'd like to even attempt..
"did you collect enough chickens?"
is better to overload an function or use different name ?
Depends on the circumstances
If it's doing the same thing just using some optional parameter(s), then it makes sense to overload. If it's doing something different, then you make a different method.
I have 2 function loadAsset from my addressable manager, one return void and other Task<T>
I would probably make the one that returns Task LoadAssetAsync or something
both do the same

okk
presumably they have different argument lists?
that's not possible
just one return nothing and other a Task<T>
you can't make two functions with the same name with two different return types but the same parameter list
it's a compile error
Think about it
oh yeah I hasn't see the action
No I wouldn't name them differently
why does the "OnTriggerEnter2D" trigger when the rigid bodies touch and not the colliders touch?
If your two colliders don't match in the matrix you won't get physics messages.
Also, rigidbodies logically combine child colliders for collision callbacks
i solved my problem with "yield return new WaitForSeconds"
wanted the player and other objects to teleport when in the middle of the portal, instead of the edge
how can line 34 throw a null reference?
are you sure its this script?
that's what it took me to
but weirdly I entered playmode again and it disappeared so maybe something else broke and it freaked out here randomly
You should read the callstack as well. Auto navigation to the line is not always correct.
!bug
🪲 To make bug reporting as quickly as possible, we made a bug reporting application for you. When running Unity choose Help->Report a Bug in the menu, or you can access it directly through the executable in the directory where Unity is installed. It will also launch automatically if you experience a crash.
📝 If your bug report is to do with Documentation, either an error, typo, or omission, you can report it by scrolling to the bottom of the page where you found the issue and click ‘Report a problem on this page’!
💡If your report is to do with a new feature idea, you can check the Unity Product Roadmaps page to see if your idea has already been planned.
For more complete instructions on how to report bugs, access: https://unity3d.com/unity/qa/bug-reporting
void FixedUpdate()
{
if (IsDodging)
{
rb.linearVelocity = new Vector2(moveInput.x * dodgingPower, moveInput.y * dodgingPower);
return;
}
else
{
rb.linearVelocity = new Vector2(moveInput.x * moveSpeed, moveInput.y * moveSpeed);
}
}
I'm currently using this as a way of moving my character across the screen. If I wanted to make my character slightly jerk forward when it's attacking by using ForceMode.Impulse2D, would I need to change the way I handle the movement here? I mean like instead of setting the rb.linearVelocity how I have here, is there a more appropriate way to handle character movement if I want my character to be affected by forces on top of simply moving it
I tried
public class PlayerController : MonoBehaviour
{
Vector2 moveInput;
public void OnAttack(InputAction.CallbackContext context)
{
if (playerAttacks != null)
{
if (context.started)
{
playerAttacks.MeleeAttack();
rb.AddForce(moveInput.right * 5f, ForceMode.Impulse);
}
}
}
}
but whenever I try to attack, everything else but the AddForce() seems to work fine
Well yes, think about your code - you're directly overwriting the velocity, so the velocity change from any force you apply will immediately be overwritten by that
A common approach is to temporarily disable the normal movement code during a dash.
Another option is to switch over fully to controlling things via forces
I'm thinking about doing the latter. Im testing it now and its moving but I still need to configure the force value and a way to add some friction
Would there be a reason to do this over using force if I want a varitety of things to affect the Rigidbody with physics?
It's simpler to control the object with
A purely force based controller will be much more complex
ah, so maybe mix and matching controls with force and directly overriding the velocity
hello guys, I am making a game for my cs project, and this is something I intend to make: https://www.gamepix.com/play/arcade-hoops
Can someone tell me if this game is 2d or 3d?
this is a code channel, though if the ball moves in 3 dimension then it is 3d
why everytime i fill my dictionary (using GenericDictionary from github for many years, no issues), then going out of the prefab and entering the prefab mode again, it's all nulls
why are the references being deleted...
Initial assumption is it's the plugin/asset/package
Hard to say without specific infos
first thought is - that's not code!
second is - possibly trying to save references to objects not in the prefab
Oo yea it may not account for this
aight thanks
perhaps 🤔
Wait a minuite.
I never let disrespect slide
bro why cant i post gifs
4 years and this server is still ahh
Don't reply to ancient posts, the trolling isn't welcome.
hey for some reason in the editor the character controller.isGrounded is fine but in build its constantly jittering?
I've read that when using a rigidbody character controller, you should read inputs in Update() and do AddForce() in FixedUpdate(). Does that apply to just WASD inputs or also jumping, sprinting, and crouching?
For intermittent things like jumping it best to in case the input is missed
you can just add the jump force in Update() because it gets stored and applied next fixed update anyway
It's well known that this is pretty much useless
Recommended to use your own grounded check
It's a capsule cast, making your own check would be a capsule cast?
The only issue I've seen with isGrounded not being consistent has been a misunderstanding how to use the CC properly (applying downward force constantly vs. assuming that it's a one time automatic check)
i'm trying to get the velocity of the player, but rb.linearVelocity returns the velocity in world-units, and I need the local velocity. Thank you
So transform the vector into local space. Transform has functions for doing so, use them
E.g. InverseTransformDirection
does that work in 2d?
Why not
Why does TransformDirection seemingly do the exact opposite of what the docs state? If I don't convert moveDir to localDir, all my movements are in world space and don't respond to the rotation of the player object. But according to the docs, the method only converts from local space to world space, even though I am using it for the opposite
I assume I am somehow misunderstanding world v local space but I'm not sure where
so, you have world space movement and you're using a method that converts from local to world space movement. you already have world space movement though so it does nothing.
anyway im pretty sure you can just do transform.rotation * moreDir to get localDir.
neat tip if you didn't know, you can multiply quaternions and vectors to rotate vectors (gotta make sure they're the right way around though)
docs dont state that though
where you seeing this
Inverse is world to local
also note that your raw input would be considered the local direction because presumably you are pressing the input based on the direction you want to travel relative to the camera's rotation so that would need to be converted to world space
so while the comments and understanding are wrong, the logic would be correct
nope, the code snippet there works perfectly. and as i said, if I don't convert then the movement is in world space
the movement is in world space, presumably from my vector2 - vector3 conversion
ok i'm posting the code for the game-does-not-start problem
please read what i said then read the documentation for the method you are using to convert from local to world space.
it's for a turn based combat in 3d, it's a little messy bc i'm following a tutorial but ask me anything
so then surely you understand that your movement is in world space because of the TransformDirection method and not because you converted from a Vector2 to a Vector3
!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.
my lord how many times must i repeat myself
if i dont use TransformDirection, movement occurs in world space
which is why I use it, so movement responds to player rotation
so you are still misunderstanding the difference between local and world space
the way you move expects a World Space direction. your input is in Local Space. if you do not convert the input from Local Space to World Space then the movement will be wrong because your input is still in local space. as in, it is a direction that if applied locally to the object would move it relative to its rotation
For example, let's say you have an object at 0,0,0 facing backwards (its forward direction is (0,0,-1)
If you move that object forward along its forward direction, that is a local translation of 0,0,1. But because it faces backwards it's world space translation would be 0,0,-1 because that is the direction it moved relative to the world
The coroutine in FighterManager has an infinite loop if the fighters list is empty
what could i possibly be missing here...
look at the previous line
because there isn't a yield return outside the foreach, right?
right
Apparently 😭
yeah apperently i forgot to drag the fighters in the inspector
thanks you saved me
Ohhhkay I think I get it now
Thanks for the explanation
btw i think i still miss something essential about coroutines, any guide or video i can follow in order to understand them better?
▸ Learn how to CODE in Unity: https://gamedevbeginner.com/how-to-code-in-unity/?utm_source=youtube&utm_medium=description&utm_campaign=coroutines&video=kUP6OK36nrM
Learn how coroutines work in Unity, when to use them & how they can be useful.
00:00 Intro
00:37 What is a coroutine
02:05 How to write a coroutine
06:09 How to start a coroutine
...
thx
does anyone know how to manually set the rotation of a bone with animations i've tried setting the rotation in lateupdate but that didn't work.
Animation Rigging package lets you override specific bones
sorry, not sure if this is the right place to ask this but i am brand new to makeing games at all and when I tried to build my game to send it to a friend this poped up. anyone know how to fix this?
are properties generally used for unity projects or do people just use public fields
they are a pain to serialize so i'm just wondering if they're worth it or not
yes they are used. when you use them depends though
main thing i use them for is changing them through UnityEvents
you can very easily serialize the backing field for a property. either you'll have an explicit backing field already so you just add the SerializeField attribute to that field, or if you are using an auto property just target the backing field with the field: attribute target like [field:SerializeField]
if you've used UI buttons before then you may have. the OnClick thing in the inspector is a unity event
alright ty
How would I be able to replace a placeholder model with the actual model I want to use?
copy over the existing model so the guid is kept (external to unity editor)
Guys, someone knows if Cloud Code Logs have a limit? It seems that the logs of my C# modules stopped appearing there :p
Yall how do I get interact to work when I press E? I watched a tutorial, but "Interact" doesn't show up on the second image
the two are not even related.
Left is new input system , the right is old input class
I just get:
"ArgumentException: Input Button Interact is not setup.
To change the input settings use: Edit -> Project Settings... -> Input Manager
UnityEngine.Internal.InputUnsafeUtility.GetButtonDown (System.String buttonName) (at <8464a637132d4cf7b07958f4016932b9>:0)
UnityEngine.Input.GetButtonDown (System.String buttonName) (at <8464a637132d4cf7b07958f4016932b9>:0)
NPC_Talk.Update () (at Assets/GAME/NPCs/Scripts/NPC States/NPC_Talk.cs:30)"
one way to use would be putting a PlayerInput component with that action asset, then you just put a method in scrip on same object,
void OnInteract(InputValue val){ Debug.Log("InteractPresed"); }
Again the two are not related
I know. I'm just posting the error message
You cannot do Input.GetButtonDown("Interact") if its not added to list on right
I know. But the guy I was following a tutorial on had an "Interact" tab on that one
"Interact" tab on that one ?
what one?
My second image
oh they did not show how to add a new entry
Nope
make the 30 to 31 , then the new entry at the bottom can be modified as needed
Ah thank you
I had already read this, but there is nothing about the logging
It seems that sometimes the logs just stop appearing, it's really strange
could be server side issue maybe, give it 24 hrs if it doesnt show up open a support ticket
yep, its weird because sometimes shows part of the logs and "lost" the rest.
im trying to change an object's material when a button is pressed, and earlier it was working fine, but now it keeps outputting this error. does anyone know why?
restart unity
alr
it worked thx
is there a way to check if given game object is a instance or a prefab?
public void AddItemToBox(Item item)
{
//if prefab, then make instance and add to list
itemsInside.Add(item);
}
if(!item.gameObject.scene.IsValid()) will work?
How do I make my NavMesh generation more performant?
I can't really pre-bake it as I generate a maze at runtime. Whenever I try to either _navmeshSurface.BuildNavMesh(); or UpdateNavMesh(_navMeshData); the entire scene freezes and doesnt recover (even after 5+ minutes).
I've tried lowering the NavMesh quality significantly by reducing the tile size from 256 to 64 and increasing the voxel size from 1.667 to 3. This still froze the scene.
What should I do? I use a default terrain with no changes to the size. My Maze uses prefabs (basically just 4 wall) were walls are being deleted for the randomness.
Probably but I question a bit the code architecture in which such a mixup might possibly happen
so this is mostly for debug
make a loading screen
generate it in a coroutine it doesnt freeze the game.
They also have this https://docs.unity3d.com/ScriptReference/AI.NavMeshBuilder.UpdateNavMeshDataAsync.html
so i can drag&drop the item prefab to the scene and using odin inspector's Button via inspector
add the item to the chest
tldr just to add items to the chests in playmode via editor to test stuff
how do you detect mouse clicks from a script that extends editor when the user is clicking at any point on the screen. The OnInspectorGUI method is only invoked as far as im aware when Event.current != null but clicking anywhere other than on a gui element doesnt trigger EventType.MouseDown. I cant tap into the EditorApplication.update because Event.current is always null.
the hierarchy window is able to do it and you can validate that it does by selecting a scene object and then clicking somewhere on another window to deselect the gameobject
im trying to figure out how to start a host from a lobby
new to this anyone have an idea? lobby works fine
"from a lobby" thats vague
also #1390346492019212368
my b forgot they switched servers
yes, the lobby package that they put into the main
are you talking about Unity Lobby
i understand that netcode is different from lobby code im just trying to understand how to get those players into the game
yes
there lots of resources on this topic. Anyway that channel linked is the place for those Qs
Loading screen wouldnt work if you'd have to wait 5+ minutes for every round you want to play. Coroutines still freeze the game - only task manager can help there.
I've tried to use UpdateNavMeshDataAsync but there was no _navMeshSurface.UpdateNavMeshDataAsync();. The _navMeshSurface.UpdateNavMesh says in its summary 'This operation is executed asynchronously'
wdym "only task manager can help there? "
also don't get the last part
I cant stop the game from running by using the stop button or the windows close button. I have to use the windows task manager to forcefully kill the unity project.
About the last part:
In the documentation it says that I have to call the UpdateNavMeshDataAsync() function in order to update it asynchronously while the game is running - this shouldnt effect performance too much and could easiely be hidden by a small 5-10 second loading screen - or at least should be. Sadly there is no UpdateNavMeshDataAsync() function to call from the NavMeshSurface script. When checking out the NavMeshSurface's functions in their code I've seen the UpdateNavMesh() function. In its description it is marked as asynchronously:
/// <remarks> This operation is executed asynchronously. </remarks>
...
public AsyncOperation UpdateNavMesh(NavMeshData data)
But it still freezes even if using this. I cant imagine that the baking operation - that takes less than a second in editor - would take more than 5 minutes in play mode on a standard unity terrain
im making a script for my player to be able to ledge jump across buildings using a raycast and everythings functional, the idea is for their horizontal velocity to gain like a massive speed boost so they can close the gap quickly but it didnt rly function well as i multiplied my linear velocity X by some multiplier, what could work better with the code?
wait forgot to comment it
what do i do i try make a project and try opening it and it says "failed to decompress" how do i fix
instead of multiplying - just set it directly to some preconfigured speed
(multiplied by the sign of the current x velocity of course)
A tool for sharing your source code with the world!
that works
another issue i had was that in my regular movement script i was using mathf.clamp so i changed it up a little bit to unclamp if player was ledge climbing like this
https://paste.mod.gg/gwtghjbyztug/0
A tool for sharing your source code with the world!
but it didnt clamp back and my players velocity was just constantly multiplied by 5
the freezing you describe sounds like inifinte loop if you have end it via Task Manager..
i finished vector3 and raycasting what should i do now
wdym you "finished" it? You mean learning about it?
Go make a game.
yes
is it bad to rely on ai for debugging?? i generally cant find the issue without it but it feels shameful
Yes it is
Ideally you should be more than capable to troubleshoot and debug directly via google and other resources
But debugging and troubleshooting in itself is a skill that is crucial to develop
You should learn how to break down the problem and step through your code to find the issue. It is very important . . .
okay, ill try fixing some errors without it thank you!
If you get stuck feel free to ask. If your trying people here will be more than happy to help, whether that be directly helping that specific issue or supporting you in how you could potentially have found the solution yourself
Especially, if the error has a stack trace to follow . . .
what is a stack trace?
i usually dont come here but ill come here next time i have an error i cant figure out
tysm!
Stack trace . . .
Im having an issue making my player controller. is it okay if i ask about it here?
If it pertains to code, sure . . .
so im having an issue where my player is sticking to walls when i jump into them. This is the script my player uses
very common issue
you're esserntially pushing your player against the wall
so it sticks due to friction
my player amteral has no friction
in real life people cannot push against a wall in midair, hence no pushing and no friction
whats the way to fix it?
show the material and how you applied it to the player
no friction materials is one way.
The other way is to not allow the player to push against a wall in midair like that
what do i set it to?
oh minimum fixes it
also what can i do to limtie player air movment?
write code that limits it
using raycasts and the like to detect when you are going into a wall, for example
public class GrappleScript : MonoBehaviour
{
public GameObject[] Grapple;
float Distance;
private GameObject NearestObject;
private LineRenderer lr;
private SpringJoint joint;
private float NearestDis;
void Awake()
{
joint = GetComponent<SpringJoint>();
lr = GetComponent<LineRenderer>();
joint.autoConfigureConnectedAnchor = false;
}
// Update is called once per frame
void Update()
{
Grapple = GameObject.FindGameObjectsWithTag("Grapple");
}
void StartGrapple()
{
if (Input.GetMouseButtonDown(0))
{
joint.connectedBody = NearestObject.GetComponent<Rigidbody>();
joint.spring = 5;
joint.damper = 0.5f;
}
}
void StopGrapple()
{
}
void DrawLine()
{
}
void NearestObj()
{
for (int i = 0; i < Grapple.Length; i++)
{
Distance = Vector3.Distance(Grapple[i].transform.position, transform.position);
if (Distance < NearestDis)
{
NearestDis = Distance;
NearestObject = Grapple[i];
}
}
}
}
``` i havent finish this yet but for some reason the object is connected to the air
it just bounces around
Well you're never calling NearestObj() so NearestObject is always going to be null and your code to connect the joint is going to cause an error
Aren't you seeing an error in your console window?
no i havent gotten any
You're also not even calling StartGrapple either
oh okay, but is it suppose to be hanging from the air still? i can send a video if that helps
so yeah your joint is just going to be connected to nothing
oh yeah...
hence - connected to the air
let me go do all of that and ill be back if its still not working
what are you expecting it to do
there's a lot of fishy stuff in this script - like the FindWithTag in Update etc
i wasnt expecting it to do anything currently i just thought it was weird it was hanging from the air, but im trying to make a grapple that connects u to the nearest object that has a grapple tag
how can i see what number something is the closest to? im dealing with floats as well. Im scaling stuff but sometimes it comes out at a number it should. it should be at 2, 1, 0,5, or 0,25.
You'll not want to have the joint created until you grapple
The number any number is closest to is itself
do you mean the nearest integer?
or maybe the nearest increment of 0.25 or something?
nearest power of 2
ohh alright, do i destroy the joint in StopGrapple or will it be fine
i supoose to put it simply
Maybe do log base 2, round to the nearest integer, then raise 2 to that power?
e.g. log base 2 of 0.32 gets you -1.64, which rounds to -2, and 2^-2 gives you 0.25
Trying to transfer over my files from another pc but it won’t load for some reason. I’m sure I did everything right any thoughts?
so to summarize, take the current scale, and do the log base 2 of it. round to the nearest integer and then take 2 by the power of that?
how did you transfer the files?
My first attempt I downloaded a copied folder of the game from my OG pc and brought it over from a usb.
Second what I did tonight, I copied all 13 of those files, put them on drive and downloaded them from gdrive.
I tried using GitHub but it says the files were too big so I didn’t go that way. Around 14 gb big
eg.
float log = Mathf.Log(input, 2);
int nearestInteger = Mathf.RoundToInt(log);
float nearestPowerOfTwo = Mathf.Pow(2, nearestInteger);```
you should only copy over:
Assets
Packages
ProjectSettings
UserSettings```
So the other stuff I delete it and it’ll work?
yes
well, maybe.
but yes you should not copy the other stuff
it is not useful and certainly may be causing the crash
especially Library, Temp, and obj
btw, not a code issue? should probably ask in #💻┃unity-talk, and perhaps check logs
really though you should use version control
instead of manually copying anything
version control is softwre, such as Git, which is used to manage software project files
and to allow easily cloning it, tracking changes, collaborating with people, etc
Is there a size limit for projects?
that's a vague question
there are many different types of version control
and many different providers
I see, I don’t really know much about version control.
But it sounds like it be easier to manage the game I’m working on
It will be easier for managing any game than manually copying files around, yes.
no for git, yes for github
there's lfs (large file storage) though
Is there a guide or tutorial I could walk through to set it up?
there are plenty online
should probably move to #💻┃unity-talk for further questions though
this is the code channel
public class GrappleScript : MonoBehaviour
{
public GameObject[] Grapple;
float Distance;
public GameObject NearestObject;
public LineRenderer lr;
public SpringJoint joint;
private float NearestDis;
public Transform GrappleTip;
void Awake()
{
lr = GetComponent<LineRenderer>();
}
// Update is called once per frame
void Update()
{
Grapple = GameObject.FindGameObjectsWithTag("Grapple");
NearestObj();
StartGrapple();
StopGrapple();
DrawLine();
Debug.Log(NearestObject);
}
void StartGrapple()
{
if (Input.GetMouseButtonDown(0))
{
joint = GetComponent<SpringJoint>();
joint.autoConfigureConnectedAnchor = false;
joint.connectedBody = NearestObject.GetComponent<Rigidbody>();
joint.spring = 5;
joint.damper = 0.5f;
}
}
void StopGrapple()
{
if (Input.GetMouseButtonUp(0))
{
joint.connectedBody = null;
NearestDis = 0;
}
}
void DrawLine()
{
if( joint.connectedBody != null)
{
lr.enabled = true;
lr.SetPosition(0, GrappleTip.transform.position);
lr.SetPosition(1, NearestObject.transform.position);
}
else
{
lr.enabled = false;
}
}
void NearestObj()
{
NearestDis = Mathf.Infinity;
for (int i = 0; i < Grapple.Length; i++)
{
Distance = Vector3.Distance(Grapple[i].transform.position, transform.position);
if (Distance < NearestDis)
{
NearestDis = Distance;
NearestObject = Grapple[i];
}
}
}
}
my script is to grapple and swing to the nearest object and it works fine but when i let go it goes back to the middle of the game
right because you're disconnecting the joint
As I was saying before you shouldn't really have the joint created at all until you're grappling
create it when you grapple, destroy it when you stop
okay!! thank you
why is my game zoomed in like this and how do i fix it
Also, don't cross-post.
thanks man
i wanna do this game mechanic where there is a wall that appears and they can pass through if they press a key. does anyone know how i can make this work?
Can be done in 3 different ways off the top of my head:
- Move the player or the wall to a different layer which has no collision with your player or wall layer
- Disable the collider
- Use Physics.IgnoreCollision
Being a dumbass and would love a pair of eyes rq,
I have this old code
Vector3 returnValue = Vector3.zero;
if (Physics.Raycast(UIManager.TrackingCamera.ScreenPointToRay(Input.mousePosition), out RaycastHit hit, layerMask: lookMask, maxDistance: Mathf.Infinity, queryTriggerInteraction: QueryTriggerInteraction.Ignore))
returnValue = hit.point;
if (returnValue != Vector3.zero)
prevMousPos = returnValue;
else
returnValue = prevMousPos;
return (returnValue);
that i'm attempting to simplify to just
if (Physics.Raycast(UIManager.TrackingCamera.ScreenPointToRay(Input.mousePosition), out RaycastHit hit, layerMask: lookMask, maxDistance: Mathf.Infinity, queryTriggerInteraction: QueryTriggerInteraction.Ignore))
prevMousPos = hit.point;
return (prevMousPos);
But my refactor is not working and I cannot tell what I am logically doing different here
Hey, I'm having trouble using Unity playworks plugin. According to Playworks documentation: Unity Playworks Plugin supports DoTween up to version 1.2.705 but for some reason it isn't being recognized
Unity Engine:2022.3.47f1
Unity Playworks Plugin version: 6.3.0
DOTween version: Tried both 1.2.705 and 1.2.690
i was like originally thinking that a random wall spawns and slides left and once it passes a certain collision it disappears and there would be at least 4 or 5 walls
its hard to explain i think i know what i would make as the concept but im not sure how to actually do it in code
The one difference I can see is that if there is legitimately a hit at Vector3.zero, you won't assign it to prevMousePos in the first snippet, but you will in the second.
Which seems like a bug in the first one
It's not clear what you're asking for help with exactly.
You mentioned several things here:
- spawning a random wall
- sliding a wall left
- making a wall disappear
Pick one thing at a time to work on
yes ill be back tonight 🫡
for soem reason my camrea is speeding up in rotation between 0 and 90 degrees
this is my camrea script
!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.
private IEnumerator Unload()
{
Debug.Log("Unloading Global Scene");
yield return SceneManager.UnloadSceneAsync("GlobalScene");
Debug.Log("Unloaded Global Scene, Status: " + SceneManager.GetSceneByName("GlobalScene").isLoaded);
}
am i stupid
seems to be due to timing, not sure why
what if you add a yield return null;
no luck, spam running the unloadsceneasync in update works but obviously not ideal
is it by chance the only active scene? not sure if unity gives you a warning in that case but cant unload a scene if its the only active one
otherwise you could check the values like isDone or progress to maybe get more insight.
https://docs.unity3d.com/ScriptReference/AsyncOperation.html for some reason they also have an extra yield return null. Maybe the actual unloading and loading of a scene happen on the next frame.
Could also try while !isDone yield return null
fuck sake
that will be it
docs are wrong
Note: It is not possible to UnloadSceneAsync if there are no scenes to load. For example, a project that has a single scene cannot use this static member.
whats wrong about that?
i dont think the statement is wrong, it just doesn't specifically say "you can't unload a scene if there are no other active scenes" as well
they do word it weirdly
I think it's wrong in the sense it fails to convey the point
apparently it returns null when it cant unload the scene, so it was essentially just waiting a frame before telling you the scene is still loaded. Maybe its by design incase people actually want to try unloading scenes while its the only active one, rather than spitting out an error or warning
I have a button object with a text as the child. I made the size of the button the whole scene, but it only reads the input, when I click on the text object inside the button
Can you Show the Inspector of the Button Object?
Also I think this might fit better in #💻┃unity-talk
Understood o7
hello could I ask is there way to slowly rotate turrets like the heads of it with code so the turret wouldnt instantly look at the enemy that its suppost to shoot but like line up?
Look at "lerping"
you can also use Rotate towards
https://docs.unity3d.com/ScriptReference/Quaternion.RotateTowards.html
what is more optimized?
rotate towards will be more reactive to a moving target
Both should have the same performance, but for lerp you have more Code for linear behaviour
both are linear
Yes if you use lerp right it is, if you just lerp a value each frame you have easing behaviour
yea the ol lerp abuse
move towards is better still as you can specify the max rotation amount
Thats why I said with more code it behaves the same, as in I also recommend rotatetowards
ok so Ill use rotatetowards
question how do i fix the pink on the water prefab? I already have the universal rp and tried to render pipeline converter but the water is still pink
im using the simple low poly nature asset
You will need to switch that material to a shader compatible with your render pipeline. The automatic converter will only work on built in shaders, if it's custom you'll need to do it manually
so you went from legacy to urp?
i'm sorry I don't get what you mean. Before this, I tried fixing the problem by searching on youtube and it told me to do this
oh wait, i thought you switched rendering backends, sorry
Yeah for the water there is most likely a more complicated shader that cant be converted, so what digiholic says applies
either get a free water shader from the asset store or watch a tutorial to make one
Alright, thank you!
all the converter does is change materials over to a URP/HDRP equivilent shader
e.g. Standard -> URP Lit
so any other custom shader doesn't work in this case
if you are lucky its a shader graph shader and that can be edited to add URP/HDRP which will probably fix it
also that project does NOT look like a good fit for hdrp 😐
they said URP
oh wait, hdrp assets in the project 😄
Yea i saw hdrp assets making me think its hdrp
Unless they are just trying anything and fucking it up more
yeah, but you can also see the shaderfile for the water, its a shaderscript
converting is possible but not for anyone at that level 😄
Found the pack, 5 years old and for unity 2018
yea this is an old ass shader
https://assetstore.unity.com/packages/3d/environments/landscapes/simple-low-poly-nature-pack-157552
I see so that's why
yep im just trying anything
First change to URP, second try to see if using a URP lit shader on a material will be enough.
This shader is not compatible with anything other than the old built in renderer.
thank you ill try this
Realistic: https://assetstore.unity.com/packages/2d/textures-materials/water/simple-water-shader-urp-191449
Stylized: https://assetstore.unity.com/packages/vfx/shaders/urp-stylized-water-shader-proto-series-187485
The asset store has a lot of things you can use for prototyping
Oo these are nice.
HDRP brings a default water system, but that is way overkill here
🙏 thank you the first one is what im already switching to
yay. move to #1390346776804069396 to ask for more rendering help
thank you appreciate you two for giving time to reply
can someone help me? the cooldown for the coroutine doesn't seem to be working. it's teleporting the player every frame instead of every 1 second
!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.
using UnityEngine;
using System.Collections;
public class UpDownTeleporter : MonoBehaviour
{
private StateHandler stateHandler;
public LayerMask teleporterPad;
public float cooldownDuration = 1f;
private bool isOnCooldown = false;
IEnumerator TeleportDown(Collider other)
{
Transform otherRoot = other.transform.root;
if (Physics.Raycast(otherRoot.transform.position - new Vector3(0, 2f, 0), Vector3.down, out RaycastHit hit, 30f, teleporterPad))
{
otherRoot.transform.position = hit.point + new Vector3(0, 0.8f, 0);
}
yield return new WaitForSeconds(cooldownDuration);
isOnCooldown = false;
}
IEnumerator TeleportUp(Collider other)
{
Transform otherRoot = other.transform.root;
if (Physics.Raycast(otherRoot.transform.position + new Vector3(0, 2f, 0), Vector3.up, out RaycastHit hit, 30f, teleporterPad))
{
otherRoot.transform.position = hit.point + new Vector3(0, 0.8f, 0);
}
yield return new WaitForSeconds(cooldownDuration);
isOnCooldown = false;
}
private void OnTriggerEnter(Collider other)
{
Transform otherRoot = other.transform.root;
if (otherRoot.CompareTag("Player"))
{
stateHandler = otherRoot.GetComponent<StateHandler>();
}
}
private void OnTriggerStay(Collider other)
{
if (stateHandler != null && !isOnCooldown)
{
if (Input.GetKey(stateHandler.crouchKey))
{
isOnCooldown = true;
StartCoroutine(TeleportDown(other));
}
if (Input.GetKey(stateHandler.jumpKey))
{
isOnCooldown = true;
StartCoroutine(TeleportUp(other));
}
}
}
}
stress intensifies
no idea, but if you crouched and jumped at the same time it would run both
well your screenshot was missing the isOnCooldown = true 😄
which would explain the cooldown not working...
it's in the coroutine
oh oops
i tried moving it but it still doesn't work
is cooldown duration set correctly in the Inspector?
it is
What did you change?
it starts the cooldown when i reach the top but not in between
i moved isOnCooldown = true from inside the coroutine (as seen in the picture) to outside the coroutine (as seen in the code i pasted)
Oh well this doesn't fix it since it only checks if on cooldown on the next trigger call so as vertx mentioned you will be able to crouch and jump in the same call since both if statements are returning true
Change your && !isOnCooldown from the statement its in to the two input statements individually
Also i would recommend using async / await over a coroutine
But that partly a preference thing
it still doesn't work
Well having the same check in an if statement after its checked seems silly, but i doubt that would be the problem
Need to be checking for Key press instead of hold.
I am using a character controller and I want to add a crouch feature. when I crouch I want it to smoothly change to both standing & crouching height. Should I use lerp? if so what type? or move towards? I heard people use different things but what would be the best for this?
Make the isOnCooldown a public and watch (in the inspector) if it stays false until the cooldown is done or not if not than its the way you handle the cooldown
dont crosspost
ok so i figured out the problem
i used one script for each teleporter instead of one script to handle all the teleporters, so the cooldown doesn't carry over to the next teleporter and it just starts another coroutine immediately
if that makes sense
Oh wait totally didn't understand this until know of course it's going to only start the coroutine after you reach the top to code to move the player all happens before the coroutine is told to wait
might be a good idea to save the cooldown on the player 😄
I mean that makes it a problem as well
Honestly that's where i thought it was :/
Edit: meaning thought the teleporting script was on the player
that's a good idea i'm gonna do that now
was i wrong here? don't remember.
i want the functionality of being able to hold down the key instead of having to press the key each time you want to teleport to the next floor
anyway thanks everyone for all the replies
for a basic inventory system how should i have multiple item types with icons should i have each object in the scene have some sort of tag etc.
even the "beginner" code people post here is confusing 💔
ScriptableObjects are a good approach. Tags don't make any sense, no
so i.e a scene with a bunch of objects that get parented to the player for picking up and each one has a refence to scriptable object? and i'm only really wanting icons i don't need names or anything.
beginner in unity is a BIG range 😄
normal programming feels like climbing stairs
game programming feels like running into a brick wall with the intention to climb it 😄
the scriptable object would hold this data (name, sprite, ect)
all the code is neat and tidy until some nerd ass designer wants juice
i know but i was just wandered if there was a better way.
we call our game designer the walking design exception
crazy the kids in high school called me the same thing 😄
That is the better way. if you have 5 apples you can just assign 1 asset with this data 5 times.
thx!
You really need to break down the whole inventory system into different parts:
- ScriptableObjects holding the item descriptions and assets (icons, names, descriptions, stats, etc)
- An inventory script for managing what's actually in the player's inventory at any given time
- UI prefab for representing the item in an inventory UI
- A prefab/script for a representation of the object in the game world, if relevant (e.g. the version of a minecraft object as it's pickupable in the world)
depending on how your game works you need to handle all this stuff separately
Having a good separation of concerns here is critical
the purpose of this code is to play a sound effect once when colliding with a pickup
AI recommended me to add the highlighted part, I tried run without it and everything seems normal to me
what's the point of the highlighted part
in what situation do i want that?
if you forgot to assign the pickup sound it doesnt end with an error
(can also just do pickUpSound?.Play()
thanks!
how do I find an inactive game object by tag?
why?
that doesnt work on unity components / Objects
ehhh, right forgot about that
I want a npc to move from inside a door, and when the door's closed there's a collider that stops the player from passing through. I want to keep the npc inactive in the position inside the door so it not collides with the door and glitches yk
like this, the npc comes from there
📃 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.
anyone has experience with dialogue system ? i am dying , i do it 3 days already and still can't make it work
check out this tutorial https://www.youtube.com/watch?v=Kez_OLjkSwc&list=PLOZ3CbLbuxPwQvkDMBiIe4v1pTwAE380z&ab_channel=KasperDevUnity
Introduction to dialogue editor with graph view tutorial series.
➤ Play List
https://www.youtube.com/playlist?list=PLOZ3CbLbuxPwQvkDMBiIe4v1pTwAE380z
➤ Tutorial Description
This tutorial will be focusing on how you can make a dialogue editor with the use of graph view.
You will also be learning how to make your own nodes so you can custom...
use Ink
it's long as heck but I recommend watching his explanation so u can improve the system and stuff
I use it already
then whats the problem?
https://paste.mod.gg/elspcnleprsr/1
but I can't make it work there
A tool for sharing your source code with the world!
i don't know why but when I load the prefabs, it can't play or set the sprite
"cant make it work" is pretty vague
I load a prefabs characterFrame (gameobject) that contain Image and animator from the addressable
then I load a sprite and a clip from the addressable before applying it on the characterFrame that I loaded previously
but the clip can't be played on a inactif gameobject.
The prefabs is actif in default and the parent is actived before I place it as childen
(starting off with that kinda info is a big help)
Get component in children returns itself?!
yes
indeed
it starts recursive from itself
You would think unity would put a flag to ignore self but alas here we are..
i've never had this issue before thankfully i do have a solution in my situation thats still clean. but i would rather figure out a better way.
what are you trying to do ? if its on the same object tree why not just make a field (set in inspector)
ye.. that was my idea.
who is this arudoyu... ? (japanese name)
Btw, i still can’t figure out where my problem, maybe because it is in async ?

did you check the console for errors
There are not error
Wait i send you all the log i get (placed)
i found a better, cheeker solution to my problem, i was trying to get a rawimage underneath a rawimage so i just made the top one an image.
this is all I get
Couroutine error is normal
It is used to check if the clip is played
how so ?
That my question
why it doesn’t work
no error should be normal lol This one is simple just dont start a coroutine on an inactive gameobject / Monobehaviour script
place logs through your Dialogue chain and see where its going
"help my coroutine doesnt work and i cant read!"
it not the coroutine problem lmao
time to open a thread in #1390346827005431951
I mean half your other dialogue stuff is in coroutines
👍
Wut ??? Not i have only 1 coroutine
I use addressables a lot and i dont really get what this script does
abstracting addressable stuff like this seems pointless
ohh..I'm used to using coroutine in mine.. nvm then I saw SelectFirstChoice
there's no best, there are quite a few ways
also #🖱️┃input-system
I have zero experience and im trying to make a game and chatgpt is doing all my code 😭 does anyone wanna help
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
im not tryong to be a coder tho i just wanted to play this game and realized it didn;t exist so im trying to mke it really quick
!collab
: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
" mke it really quick" 
trust someone with no experience to tell me a game is "real quick"
no thanks. You can make a post on #💻┃code-beginner message
never too late to start learning how to post in the proper section 
balright im not a discord no life bro
im just tryna get some input
aren;t i in code beginner right now
for code questions for someone working on code, you're not asking a code question.
nav posted a message link, not a channel link
advice on what ?
im in high school and im doing this cause im bored
my project thing
is this discord like for people who do this for work
one doesnt make a game out of boredom, quite the opposite
its a community for all different stages , only thing is you don't request work
where do i ask my question
we are here to help you make your own thing, not make stuff for you
so ask it
what template should I use for a madden ultimate team type game but only pack opening so it's basically slots
what do you mean by "template" exactly? you're not gonna get a functioning game just out of a template
oh
all that is stuff you have to make
like 2d or 3d
well, do you want to make it in 2d or 3d
we could do without the unnecessary reaction gifs/emojis, thanks
there are templates on asset store but very unlikely its specific to what you want
whats the render pipeline thing tho
who cares bro shut up
nah yall are annoying wtf
literally in the rules
just leave then
if you don't like to adhere to community rules, find another place to spam
who cares just stop making me feel dumb and answer the question
was going to.. and then you insulted me...
yall are sad bro this is genune no life discord rules yall nt even mods lighten up
if you ask help, being kind is the first thing you should know
"how not to get help 101 "
this is hilarious
ive been nice but yall keep being rude
You took everything as negative so you are the only one escalating to hostile
yeah, and that person actually took it well too lmao
oh please..if this is being rude, don't be on the internet..
@ember arrow Enough already, you're burying your own question.
alright can i ask it again and get an asnwer so i can leave the server
should i use a 2d thing or the built in render pipeline
The answer is, no template.
idk wat the redner thing is
Use URP.
how do i not choose a template
the first three are Empty. hence the name "Core"
Choose Universal 3D in your case
i dont know what core means im new to this like i just downloaded
I just said what it means lol its literally a blank template (no assets or example files)
if you want a 2d project you can use one of the 2d templates
You can choose either 2D or 3D and you're not locked into your decision. Behind the scenes, it's really just the same thing with different settings that can be modified anyway.
If you're trying to replicate a game, look at what they do, if it's 2D/3D.
3D is just cooler 2D
depend but yeah also, it is harder to code
it's not really harder, it's just different
there are different skills and mindsets involved
nahh it really is the same API for the most part
all you're doing is considering Y is usually gravity , and ZX is your movespace by default (ofc depends on game style)
Unity "2D" is just 3D with sprites on a "stage"
As i call it fake 2d

Btw if i modify sprite deph, will it affect the sprite ? (I think yes but to be sure)
sprite deph?
Z yes
but Order in Layer takes precedence
layer, then order in layer, then sort axis
