#💻┃code-beginner
1 messages · Page 632 of 1
If you're not getting errors highlighted in red you need to configure your !ide
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
•
Visual Studio (Installed via Unity Hub)
•
Visual Studio (Installed manually)
•
VS Code
•
JetBrains Rider
• :question: Other/None
lemme do that :D
where's your setturntype in inspector?
why would seeing that matter? we already know what the errors are, they just need to configure vs code so they can use the quick actions to import the correct namespace
find in Hirachey where did you use this script named "SetTurnType"?
if you've followed the steps in the guide the bot linked but vs code is still not showing errors then go through the troubleshooting on this page: https://unity.huh.how/ide-configuration/visual-studio-code
again, this is entirely irrelevant
oh unity isnt showing any errors either
like its fixed
can you screenshot what the code looks like now after completing those steps?
okay so you've now added the correct namespace, but if you comment out line 5 does it show errors in the code? if not then you need to go through the page i linked
okay good, it's properly configured now. so you're good to go
yup :D
Why are you using Console.WriteLine
it's been a long night Sorry
Hey everyone! I am new here, and i have a quick kinda question lol.
My current bullet script (2d tower defense type game) when i'm firing a bullet it's homing on it's enemies (which is wanted) but my issue is that when the enemy turns, it's causing it to not keep up the same speed as when it's fired? if that makes sense.
How would i go about making it "turn" just as fast as it goes when it comes out of the firing point on my turrets gun... This is the code i'm using.
which word?
Like, you know, these games that when you hover about a specific highlighted word shows a tooltip to explain it
Sorta of like adding a link to it??
🔴 UPDATED Tooltip Video Tutorial https://www.youtube.com/watch?v=YUIohCXt_pc
🌍 Get my Complete Courses! ✅ https://unitycodemonkey.com/courses
👍 Learn to make awesome games step-by-step from start to finish.
Series Playlist: https://www.youtube.com/playlist?list=PLzDRvYVwl53sN4Ewi_f-iyWZzWNmLG_bI
Grab the Project files and Utilities at...
This I know how to do, I think. But I don't want it to happen over a button, I want it hovering over a specific word
This is more like it, but, uff, I am finding it pretty hard to follow lol
Ouh, I can use TMP_TextUtilities.FindIntersectingWord to check over what word I am hovering over
Ya, she's just using a lot of stuff that I do not quite understand, in a row lol
I mean the main takeaway is learning about the <link> and FindIntersectingLink util func
So, I would add the "<link=MyLink> Whatever word <link>" on the text box and when using FindIntersectingLink I can get "MyLink" as a value when hovering over it and do whatever I want with it
It's that right?
GetLinkID() returns you that MyLink
the rest is just finding it position wise
Oh, so the other returns the Link index?
yea
I have to convert that to ID
Got ya
Thxs
So the index is just the position it has on the text between all other links?
So I could like do something if you click the third link on a text?
the index is for stored in the LinkInfo struct
So I am not meant to use that directly most of the time right?
Cause feels like SUPER specific
linkInfo is an array
so all the links are stored in it
TMP_Text stored all that stuff
Mmm, so if it's an array, would that make so I cannot modify the text later?
Cause those are like fixed size, aren't they?
idk exactly how Unity does it.
I'm assuming updated as you change the tmp_text it gets updated in the array if links if some are present, its whatever method they are using to do rich text and parse tags
Ya, seems like I don't want to get too deep into that
If it works, don't touch it 🤷
if you change ID it probably updates accordingly thats why the index so you always get whatever ID from indices
I saw there is an Official Behavior Package for unity 6, But my whole project is in unity 2021.3, Is there any way to use that project in unity 2021.3?
Unlikely. You'll need to upgrade.
then there is no workaround for it, right? actually its almost impossible to upgrade right now, this is already a huge project. Maybe i have no way around
I'd assume that there are good reasons they don't support it on earlier versions. Possibly because there are dependencies that require a later version.
yeah, i guess you're right
Did you try adding it by name as suggested in the docs?
Looking at the package change logs it was supported by 2021 at some point, so perhaps you can use it.
no i didn't. Let me check it out, thanks
i have a scriptable object with a id field, how do i auto increment this or auto generate unique value when create one ?
Is it being unique a requirement?
yes it is id
is it fine if it's hash instead of integer?
add Reset() function
In Reset() you can get the editor unique GUID and store it as a variable using AssetDatabase.GUIDFromAssetPath(AssetDatabase.GetAssetPath(this))
i suppose just gen one in awake ?
no idea what im reading
A new ScriptableObject is created as an asset via the Create Asset menu in the Editor
but seem awake with the new GUID will do
That should give you GUID back, convert it to and store it as UnityEngine.Hash128
no Awake will not work since Awake will be called when you start the game as well
Reset is always called once when you create a new ScriptableObject
reset doesnt seem to be called at all
how is this the documentation for this 😭
surely they can be more descriptive then that
oh right, I might be mixing some stuff up here. You can rename the function to something else and add [ContextMenu("Initialize")] above the function name. Then you can right click the ScriptableObject after you created it and click Initialize to set it.
I could've sworn Reset would be called on ScriptableObjects as well 🤔
Not at a PC with Unity atm so can't verify on my end
Could use OnValidate and register the instance with some kind of manager and assign an id at the same time. If it wasn't assigned yet.
OnEnable might work too
onenable runs at runtime no?
https://docs.unity3d.com/ScriptReference/ScriptableObject.OnEnable.html
you can check the docs and see, scriptable objects dont work the same as monobehaviours
Should be running in the editor too(for SO, but might be for MonoBehaviour in the scene too)
what in that doc actually has that answer? I might be missing it cuz i did check first
It's called when you create the SO asset (from the project folder)—actually, twice: once when you create it and again after naming it . . .
It says it runs when it's loaded which implies yes but that details behind that not being stated made me feel iffy
This function is called when the object is loaded.
I dont remember exactly when objects are loaded, but iirc if you load a scene and something has a reference to the SO, it will load it.
probably on first de-serialization yeah
i assume loading an assetbundle with one procs it when the bundle loads too and such
usually I just make a button like with ContextMenu to generate an ID
dont think ive really used the unity messages for scriptable objects much cause i barely remember how they're called too, and it's not really needed a whole lot
how to fix error. i need line of code or some idea for change this script "error cs0122 inputmanager is inaccessible due to its protection level"```CS
void Update()
{
_rb.velocity = InputManager.Movement * moveSpeed;
}
public Rigidbody _rb;
[SerializeField] private float moveSpeed = 10f;
Facts. It's much easier to create a method that searches for the type of SO, puts them in a list, then creates an ID for those without one . . .
What's InputManager? Is it your own class?
You need to put the correct access modifier for your InputManager . . .
no
i just try my self find best script for move with rigidbody
and i found this
from tutorial
i trying but in him screen hes code works well but when
i write to code this it dosent work
yes
Share the tutorial and the exact place where they use the same code.
Show your Support & Get Exclusive Benefits on Patreon (Including Access to this tutorial Source Files + Code) - https://www.patreon.com/sasquatchbgames
Join our Discord Community! - https://discord.com/invite/aHjTSBz3jH
--
Let's break down and analyze the most popular ways to move your player in unity, and talk about the pros and cons and when ...
Make sure you follow along and copy exactly what they wrote . . .
It seems you missed a step that they did . . .
I dont think they actually show that part of the code, but honestly this tutorial is one of the shittiest ones ive seen in a while
oh
InputManager is probably some separate class this person wrote, I skimmed through and didn't exactly see it. Either way you'd likely want to just use the new input system and follow an actual tutorial on setting that up.
If your use case is simply enough, you could just directly assign the velocity to be the input * moveSpeed but theres a lot more to actually consider than what this tutorial is saying. And also you're using 3D from the looks of your code
that video above barely even qualifies as a tutorial honestly, it's just someone listing out ways that an object can be moved while giving borderline wrong information about it. it's sad what people publish
how to make Character Controller go through walls? i need script
i just need somethink like box colider "is trigger" but in character controler
I just need a quick bit of help.
What is the name of this type of operator:
Float _float = _bool ? 1:0;
ternary
thanks
i thought scriptobject value can be change runtime ?, i have this one dragged onto the script
cs public PlayerDataSO playerData;
and this update it: cs playerData = SaveSystem.LoadLocal<PlayerDataSO>("Save.sav"); Debug.Log("load:"+playerData.characterId);
the debug show it get the correct value, but the scriptobject value unchanged ?
what is saveSystem.LoadLocal?
And scriptableobjects reset on every new runtime, just fyi
it load the json file with this
T data = JsonConvert.DeserializeObject<T>(File.ReadAllText(relativePath));
thats giving you a scriptableobject
not setting values on one
playerData = is changing your PlayerDataSO reference
not sure i understand english here.. i drag the object to the playerData, what is the reference of the PlayerDataSO you mentioned ?
JsonConvert.DeserializeObject<T>(File.ReadAllText(relativePath));
this is making a scriptableobject
it's not putting all the values from your json into one
ok so that can create a new one, but after that playerData = should set the dragged one right ?
playerData = JsonConvert.DeserializeObject<T>(File.ReadAllText(relativePath));
this sets the playerData to the one it makes via code
whatever you drag in doesnt matter
does any one know a active ragdoll tut that i can follow because i cant find one
When you drag the SO into your inspector, its an actual file holding the class with its values. When you deserialize with json using your textfile, it will create a new version for runtime. You then either have to assign every field of the json object to the inspector dragged object, so you should write your own constructor/update method or you just reassign your inspector field with your code using the new generated runtime object holding the json values. As long as you do not assign the values of your current file, your inspector dragged object is useless and not used at all. Its just another SO using your class next ot the json serialized object also using your class, but with its own values.
ah ok so thats the reference meaning
If you use playerData = YourJsonObject, you jsut replace the reference, not assign the new loadeed to the SO, that was in there before
actually have to re assign each field then
or just use your loaded one. Why would you reassign it?
are you using the dragged one anywhere else?
yep, its the player data used to hold and update then save thorughout the game
Having a data manager loading that SO class from json into a static object would make more sense
so you can access it from anywhere and only update/save the values when needed to the file back
SOs are not meant to be data holders throughout different runtimes, they always reset (be careful, they update and save in editor but not in build)
perhaps using a scriptable object for a runtime saved/loaded class is a poor design choice 🤔
(as its causing confusion)
I used SOs to create quests and relations upfront, and then have a json equivalent to update those SOs on runtime and save back the latest state to the json equivalent, so you can use SOs inside a custom node editor for example and update the whole quest queue with player data. But you can never rely on them to save for players. Its usually more a setup/default settings thing, using SOs rather than updated state records
if everyone says so, cause im actually looking at a save system tutorial first time rn
this.transform.position = new Vector3(speed * Time.fixedDeltaTime, -11f, -79f);``` Why is my character move backwards in Z direction, it should move in X direction only ( The direction of left and right.)
is your camera rotated?
I am sure, unity is not magically turning x into z 😉
No, it is not, it move my character backwards just a little bit.
over time or initially?
this code will only change world X so must be something else or you are mistaken
over time.
yeh, I agree, something else is moving your character, maybe its using physics and slips away slowly?
I don't know what you mean.
It did use rigidbody tho.
if you use physics, you cant use transform.position, because thats like skipping physics and then teleporting them to a new position. so you should check, if your rigidbody is using gravity and physics and if it will just move by itself with your entire code disabled
Sorry, I post the wrong function, the character is moving backwards is present when transform.Translate was used.
still ignoring physics afaik
and maybe show your function, so we can check against the correct one
this.transform.Translate(speed * Time.fixedDeltaTime, 0f, 0f); here
it move my character backwards.
And if you comment that out, its not happening?
be sure, that your character is facing in the correct direction globally
What did you try searching?
Can I access this Color from the shadergrph?
Check what component it is, google for the docs from unity, get the answer 😉
You would pass it into the shader as a shader property
Why unity is failing to recognize my script in the visual scripting global namespace?
This is my scrpit file. Am I missing any settings ?
public class TestScript : MonoBehaviour
{
[SerializeField] private bool Check;
public int speed;
private void Awake()
{
}
private void Start()
{
}
private void OnEnable()
{
}
public void PrintHi()
{
Debug.Log("Hi");
}
}
Does anyone have an idea why do I have C# script in Unity as Miscellaneous Files and not Assembly-CSharp? I have Visual Studio set in my preferences in the project, and I have installed "Game development with Unity module" in Visual studio installer
Wdym by "failing to recognize"?
Newly created C# files are not showing up here for some reason. I'm fairly new to visual scripting, and I think I'm missing a setting or something.
First thing to do is make sure your script is saved
Second thing to do is look in the console window and make sure there are no errors
!vs
If your IDE is not underlining errors in red or autocompleting code,
please configure it using the link below:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
go through the guide again
The script is saved and my console has no errors at all.
According to this is it looks like you need to use the [Inspectable] attribute, right?
what does this mean
it's a bug in the editor
its an editor error, ignore it or restart if its bothering you
oh i see
okay thanks
thanks
Actually, we need to regenerate the node library for the new C# files as per the documentation. Also, [Inspectable] is for something else.
Thank you 🙂
active ragdoll tuts for unity
Any ideas why this works, but if I run the AddListener() in Awake function it throws a null reference?
Likely because GameManager.Instance isn't set yet
I thought you were supposed to use the Awake but nevermind I guess
Rule of thumb:
- self initialization goes in Awake
- Initialization that relies on other things already being initialized goes in Start
Rule of thumb: reference yourself in awake. Reference other objects in start
Okay I see why now
So, the Game manager would set instance in awake (a variable on its own script), while this script would add listener in start so the game manager has guaranteed to have run by then
My game manager is instantiated in Awake as such
public static T Instance { get; private set; }
protected virtual void Awake()
{
if (Instance != null && Instance != this)
{
Destroy(this);
}
else
{
Instance = this as T;
DontDestroyOnLoad(this);
}
}
Yes, and the order objects run Awake in can't always be guaranteed
Another object might get initialized first, which would run their awake before this one runs to set Instance
Yes I see thanks
use Instance = (T)this; instead 🧠
i bet my most said things on this server are about (T) casting and unitask 😐
HI i try a CodeMonkey Tutorail (but not copy him )
And I try make a Instance spawn OnCreate but "singleton don't exsist"
OnUpdate its ok
What is the specific error, and what line
EntityRef entityRef = SystemAPI.GetSingleton<EntityRef>();
10
InvalidOperationException: GetSingleton<EntityRef>() requires that exactly one entity exists that match this query, but there are none. Are you missing a call to RequireForUpdate<T>()? You could also use TryGetSingleton<T>()....
The error is giving you very good suggestions
but really you probably just missed something in the tutorial
he did that OnUpdate
becouse he create a bullet
i want create something at the start
Its look like that that OnCreate is call before EntityRef
EntityRef is yet not ready
but how to solve that ):
Again presumably you missed something in the tutorial
He did that OnUpdate And OnUpdate works fine too
but i want do it At start And only once
then use OnCreate
You can't in OnCreate since OnCreate happens before your entity world exists. First all sytems are created calling OnCreate, then your entity world is loaded by SceneSystem.
Only safe place to access that singleton is in OnUpdate and making sure your system has state.RequireForUpdate<EntityRef> to make it wait until Singleton has loaded in
Ok SO how can i make entitis for start ?
i don't wanna make some "IFS"
@iron wind Why i can't see a "cat" at console
Its shoule be call before OnUpdated
I know that its not good way to try execute that code XD but i just wanna test every "state of states "
Do you have RequireForUpdate on that system?
show the OnCreate function
I found plenty of resources changing the search slightly to "active ragdoll unity tutorial", maybe you can try more specific keywords like that instead of "tuts for unity"
hopefully to God they're not actually searching "tuts"
@iron wind i have no internet now. I will give you info latter (i AM on the phone)
i made a tilemap and filled it with a grass tile. unfortunately, while playing, there is occasional sparkling of gridlines, suggesting that there's some alignment flag i need to set
you need to use a pixel perfect camera
i thought that i was. i'm brand new. how do i check please
Do you have the pixel perfect component attached to your camera?
ok ty
pixel snapping is turned on. i don't really know what pixel per unit value to use
i also don't see how to set that for the tileset
i set the reference resolution to the game's current fixed screen resolution
it should be identical to your asset PPUs
that's set on the import settings for the sprites themselves
well i don't see a way to set that for a tileset, so i don't know how to assert that
wait ... you're not saying i have to remove the tilesets and re-add them?
I am not saying that, no
ppu is how many pixels on the sprite equals one in-game unit
are grid cells one in game unit in size?
assuming you didn't change the default on the Grid component
got it. that's the (first) part i was missing.
okay. my tiles are 128x128. my pixel perfect camera is 128ppu. pixel snap is on. my grid is still sparkling. what's next?
I'm not sure 😰
Might be better to ask in #🖼️┃2d-tools
oh, wait. my game has camera zoom effects. if pixel perfect zoom still produces grid sparkle, ... hm.
have you set ppu on the imported asset?
select the asset and look at its import settings for a ppu setting
it kinda is just pixelcount, it tells unity how to properly scale your sprites
so, the pixel perfect camera broke a different thing that i had for dynamically scaling the camera sometimes. i'm about to go just turn that off, but before i do, is the pixel perfect camera the only approach to this? there isn't like an AA mode without it or something?
-
the pixel perfect camera's job is to ensure that movement and rendering align perfetly with the pixel grid..
this prevents subpixel rendering that case blurriness or distortion.. -
ofc its not the only approach.. you can find other assets or roll your own solution..
-
no single AA setting will solve all the issue's that pixel-perfect camera addresses
Hello, I need help. I want to create a hotbar and inventory system in my 3D first-person game, almost like in Minecraft. However, I'm not good at coding and usually follow tutorials or use AI. I've tried both methods but haven't found a good system. Do you have any tips?
Don't crosspost
Don't crosspost please.
Also, genuinely curious when people ask these kinds of questions, what kind of "tips" are you hoping for?
Usually, scripts they can just place directly into their projects that do everything
I don't know... maybe tutorials or assets? Sorry for just asking.
Just searching "Unity Inventory System" will provide several
You've already claimed that no tutorial was a good enough system (not believable) or AI didn't help (believable) what else can we suggest?
- Take the time to learn how to make games generally ( !learn ), to the point where you can confidently design and develop your own systems unassisted
- Buy an asset off the asset store (which will still require #1)
- Pay someone to do it (which will also require #1 if you want to modify it in the future)
im trying to add a animation controller but i cant open the project window
every time i click either the hotkey or navigate through the GUI it does nothing
am i missing something?
Probably #💻┃unity-talk
thanks ill ask there, since i already tried the resettiong layout thing
can somebody explain this error i was working on something different and out of nowhere this showed
You have two namespaces with a class named Random. UnityEngine and System. You need to tell it which one you want
Or get rid of the namespace you didn't intend to do
but why it showed up now
i never had this issue before
Because you have two namespaces with a class named Random imported
ok thanks
Hi, I´m sorry if this is not the channel for that, but does someone have a good tutorial, be it video or written, to recommend for dialogue systems and inventory systems? The plugins I was using are not working properly and I´m desperate enough to try to do everything from scratch...
I´m working on version 6000.35.f1
there will rarely be a tutorial that does exactly what you need. if you're going to write it from scratch, well simply start writing and google what you actually struggle with. a dialogue system is a string you display on screen. an inventory is a list of items. your game design heavily changes what you actually do with these systems
also someone else asked the same thing slightly above. #💻┃code-beginner message
i'm assuming you want unity's random so you can put UnityEngine.Random.Range
Hey, I am not quite sure where to ask quastions about problems on here
Oh, sorry, my game is a 2D click and point where you go around collecting flowers and meeting people. Most of the actual tutorials I found were years old and I wasn´t quite sure if it would be a problem or not with unity´s version since I´m quite green to coding.
So following an older tutorial won´t be that much of an issue?
what did you type in google
to find the proper tutorial
cuz if you typed "how to make point&click game about collecting flowers" then you wont find any thing
just divide it into parts like "how to detect clicks in unity" etc
the code itself wouldnt be too different although I havent used unity 6 yet. i know some things got renamed like rigidybody's velocity to linearVelocity.
i really advise not following a tutorial blindly if possible. it'd be much better if you implement a feature and google or ask what you actually need help with. Like "collecting flowers" is not the problem. The problem would be like detecting if the user clicked on or collided with an object.
2d Dialogue system for unity tutorial, the youguest one I found was from 2022
From google
what is 2d dialogue system
how is 2d dialogue system different from 3d dialogue system
The Ui I assume...
UI is UI. still, what part of the UI do you struggle with? google or ask specifics about that instead when you get to them
A dialogue system can literally be a list of strings, and populating a textmeshpro component with the string
Yeah, I´ve made a few minigames with the colliders and rigidibody, I think the biggest problem I would have would be in the dialogue system directly since it´s from what I´ve seen mostly script based. I´ll try following the tutorials I found then and come back when I have questions on something specific.
Thank you all!
if you dont know c#, you should follow a course on that. there is a link in the pins "intro to c#". tutorials generally have awful code
and following a tutorial where you dont actually understand what you're writing just isnt going to end well
I´ll give it a look, but I am leaning C# at uni, it´s just not a great class ;-;
Thank you!
Hi, i have found out today, that after clicking a button once, it cannot be clicked again for some reason. Not that it clicks and does nothing, it cannot be clicked, and i guess it has something to do with UI overwriting, as all my UI is non interactable all at once. I have no clue why tho, it must be something to do with the function, but that function does so many things its hard to find
You don't have to wait until class to learn. I say do some personal studying . . .
Try again and look at the button’s inspector this time. If you see the interactable tick go away then you have a script/onclickevent disabling it upon clicking
The whole UI gets disabled
You mean the game object gets set to false or the component itself?
Bad wording on my side. Not disabled, but i just can't click anything, and interactable is still on
its like something that i did is blocking the raycast
But it was a long time ago and i just noticed it now, i don't remember what could have happened
There could be 1000 possibilities as to what’s happening. As long as whatever happens is happening after you click, it’s due to your onclickevent. You would need to see what exactly it is
Maybe send the actual method and show the issue with a picture/video for better help
I saw, and...
wait....
If i click any button once, everything becomes unable to be clicked....
Do those buttons share the same onclick method?
they call completely different methods unless.....
Yea, they at some point call the same function in one script
Then send the relevant !code and describe/show the issue better because i’m still unsure what you mean by “unable to be clicked.” There could be many reasons why
Well bots down
look at the event system to see what you're hovering over
OHHHHHH
FOUND THE MOTHERFUCKER, TIME FOR TOTAL ANIHILATION
It was an invisible button for my menu that for designing purposes i decided to have in the same scene
it was supposed to be 'click to continue' kind of thing
i forgot to disable it
Yea, event system helped
Thank you both a lot
i would not have figured it oput any time soon
Was that button on top of all of the other buttons?
As you can see, this isnt part of a standard UI, so yes, i only wonder why it let me click for the first time
but well, i don't think i wanna know
If you can afford it, Pixel Crushers’ Dialogue System for Unity is fantastic and requires virtually no programming experience.
i added a pixel perfect camera. i set the sprite's ppu and the grid's both to 128, which matches the tile size. i set the camera's reference size to 2k, which is currently the game's fixed render size. i am still having grid edge issues. i am too new to know what to look for.
How would I find the Damage script without a object?
public int amount;
public override void Apply(GameObject target)
{
target.GetComponent<Damage>().damageTaken += amount;
}
What do you mean by "without an object"?
If you mean access class fields, the class itself would have to be static but I don’t see why you would even do that…
I figured it out after a bit but I mean. Like trying to get the script itself instead of through the object cause it don't exsit
Wdym exactly by "getting the script itself"? Do you know the difference between a script, a class, and the component created from the class?
and about object oriented programming nature all together
Also by creating an instance of the script (object), you are essentially doing just that
does setting hte velocity of an rb to something as little as 0.01f have a chance to round it down to 0? or say something near 0 like 5.960464E-08
Well 0.01 in particular is not a number that can be cleanly represented in binary so it will certainly not end up as exactly 0.01
Floating point format explorer – binary representations of common floating point formats.
However it will not be rounded down to 5.96e-8, no
i see, thank you
ah, i still had anti-aliasing on
hi i got
Assertion failed on expression: 'IsFinite(distanceAlongView)'
Invalid AABB a
Invalid worldAABB. Object is too large or too far away from the origin.
And i have no idea why (there is only 15 entitis and all of them are close )
Does it point to your code? Share the callstack
The error details please. The bottom of the console.
The error don't stop a program
Its still running so there is like 999+ of them XD
does anyone know why this enemy turns invisible when flipped o nthe x axis?
- Might want to ask in #1062393052863414313 . ECS is not a beginner topic btw.
- Share the error details. You should know to do that before even thinking about ecs.
know what ?
How to share the error details. Or rather how to share errors properly.
its looks like that i can't do new in the LocalTransform for somereason
SystemAPI.SetComponent(ballEntity, LocalTransform.FromPosition(new float3(i, 0, 0)));
if i first make a
pos=new float3(i,0,0)
SystemAPI.SetComponent(ballEntity, LocalTransform.FromPosition(pos));
Then there is no error XD
I see no connection XD i just join that forum 2 days ago XD
So i don't know the "ruls" etc
And i need ECS for performance i already try normal gameObject and when i had like 400 object there was already less that 60 fps
You need to read the rules before posting then.
But anyways, it's not part of the rules. It's just common knowledge. And I even told you how to do it here:
#💻┃code-beginner message
Might want to learn to use profiler too. You might not need ecs at all.
Yep i know but i said that there is no bottom of the console XD
Becouse the bottom is in the place when i stop it
if i will stop it 2 times it will be dif
I did use profiller
But i generally wanna make some kind of TD with at least 200enamy at screen
So if i just made 400 object NO graphisc close to 0 logic and i already had 40 fps that means that i need something else (:
guys i need help does anyone know why the win screen isnt appearing after all the waves are finished and there is no enemies left?
Probably because your material/shader doesn't support it.
!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/, https://scriptbin.xyz/
📃 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.
I don't understand what you mean by that. The bottom of the console is below the error list.
Well what did you discover in the profiler then?
Physics + orther
The part that says "assertion failed ...". This would usually have more info and/or a callstack.
It's the error details space.
Then perhaps you should have optimized the physics.
Anyways, I'm not here to change your opinion, but if you need help with DOTS(ECS), you'll need to ask in #1062393052863414313 .
Just know that it's not a beginner topic.
i tried flipping a different object with the same material and it was still visible, just that it became dark (unaffected by light i guess), how/where do i check for shader?
I did only use collider so This is unity "function" i see not too much space for optimization
Am i wrong ?
In your material.
You're probably wrong. The game wouldn't lag with just 400 hundred colliders.
what do i look for
This is a pretty basic problem but for the life of me I can't figure it out; my guy won't jump while moving and idk why. can anyone help? it's cool if not
Can't say more than that without seeing the profiler data and you scene setup.
what if there is constant collision ?
Is there any reason you're using that material and not the default one?
i work on this project with other people, someone else is responsible for dealing with setting up the light and stuff, so i just made this material to make the object always lit so i can see it properly when testing
If they all overlap and collide with each other, it might, but this wouldn't be proper behavior in ecs as well. If the units can go through each other, make sure their colliders don't process collisions with each other.
Also, dynamic objects need an rb.
There are many small things like that that you need to learn. Before thinking about ECS.
This has nothing to do with your code - you've got things that are out of scope of the physics system and causing math errors. Something's either really big or really far
It's trying to do math on numbers too big for the variables to hold and it's causing a cascade of problems internally
But how its possbile ? the position is less that 50
Then just remove the material entirely. It would use the default one, that should work correctly.
The position of what? The error doesn't say what object is the problem, it actually can't because of the exceptions that are coming up
The only object is that ball
Only that code create any object
and if i change variable "i" to that
SystemAPI.SetComponent(ballEntity, LocalTransform.FromPosition(new float3(5, 0, 0)));
there is no error XD
thanks, it doesnt disappear now, but is there no way to modify the unlit material to avoid it from disappearing and keeping it lit?
DOTs could very well be the cause of this, I have no idea what is and isn't available. Maybe there's some sort of race condition with the loop causing a NaN? Might be better to ask in #1062393052863414313
Try using the sprite unlit(or default unlit, don't remember the name) shader, instead of particle shader. Also, this is not a coding issue. Ask it in an appropriate channel next time.
oh hey can anyone help me with my game why isnt the win menu opening once there is no more waves or enemies?
!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/, https://scriptbin.xyz/
📃 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.
A tool for sharing your source code with the world!
you've got a lot of logs there, which ones show up and which ones don't
How far does the code reach
only this one at line 102 shows up Debug.Log("All waves finished! Checking win condition...");
the rest dont show up at all
Then if (currentWave >= waves.Count - 1 && enemiesAlive == 0 && enemiesLeftToSpawn == 0) is never true when that line runs
is the problem like theres too much code and its lagging the game
Try logging the values of those variables before the if
and see which one isn't what you expect it to be
Use the profiler to troubleshoot performance issues.
Also, if you are logging too much, it could have a big impact on performance keep only the logs that you need right now and commend or delete the others.
Make sure you don't have errors spamming in the console as well.
Also, there's no such thing as "lagging because of too much code".
im only getting this log
Then if (currentWave >= waves.Count - 1 && enemiesAlive == 0 && enemiesLeftToSpawn == 0) is never true when that line runs
Try logging the values of those variables before the if
and see which one isn't what you expect it to be
One tip: share the whole console window when want to show logs.
like enable every single log?
No. Take a screenshot of the whole console tab/window.
At least show that you haven't disabled errors and whether or not you've collapsed multiple logs into one
If not sure what to share, it's always better to share more than less.
Like a whole screen screenshot can be good enough for starters.
That's still not the whole console tab, but at least we can see that you have the messages collapsed and one message has been printed 40k times. If it was in a short period of time, of course your game will lag.
Still not showing if you've disabled errors
is that errors?
You don't have any now, but do keep that toggle enabled all the time.
Okay, good to know they're not enabled, even if there aren't any right now. You should probably toggle that back on
I'd start with reading the messages that you get. Especially ones coming from the engine. And possibly fixing them.
Just update for @polar acorn
public void OnUpdate(ref SystemState state)
{
EntityRef entityRef = SystemAPI.GetSingleton<EntityRef>();
float3 pos = new float3(0,0,0);
for (int i = 0; i < 15; i++)
{
Entity ballEntity = state.EntityManager.Instantiate(entityRef.BallPrefabEntity);
pos = pos + new float3(1, 0, 0);
SystemAPI.SetComponent(ballEntity, LocalTransform.FromPosition(pos));
//SystemAPI.SetComponent(ballEntity, LocalTransform.FromPosition(new float3(55, 0, 0)));
}
state.Enabled = false;
}
Now there is no error XD look like i is illegal
Like I said, weird DOTS for loop race condition shenanigans
Still strange becouse new float(i,0,0) should create object at exacly the same way
And BTW objec was fine before too (there was error but in the scene everything looks the same )
We don't know if you're doing ecs correctly. There might be other components that your entity is missing causing the error. Or it might not be related to runtime at all. This is all very ECS specific, so you should ask in #1062393052863414313
I have an enemy prefab with an enemy movement script, it has a public GameObject player variable. The editor won’t let me assign the instance of the player object that’s in my scene. It says type mismatch. How is my player’s GameObject a type mismatch from public GameObject player; in my script? I don’t understand why the editor is complaining
I can drag/drop my player onto the EnemyMovement component (on enemy) but it won’t let me apply it to the prefab
you cant reference scene objects from prefabs
you'll need to reference the player another way, could be through the singleton pattern even. although you shouldnt use GameObject, use the type you actually want to get from the game object
Dang, ok. I’ll have to rethink things. Thanks!
I had it as public Transform player; but changed it to GameObject before I knew you cant reference scene objects from prefabs. I really just want the player's transform available to each prefab Enemy object that I spawn. Would making the player prefab also work?
no since that would just let you reference the prefab of the player, not the one that is in the scene
have the thing that spawns enemies also set the players objects on a public field
does unity do what web developers would call tree shaking? if i add some asset set into my project, and then only use half of it, do i need to manually remove the other half to keep the binary size down, or does the unity linker handle it for me
or give it a method you call after instantiateing the enemies that you can pass stuiff they need at runtime to
with a few excpetions, only assets referenced by scenes or bundles included in the game get included in the build
nice.
You're mixing up assets and code compilation. Linker is usually mentioned in the context of code compilation and is unrelated to assets.
hy i probably need a second eyes for this, do i miss something? everytime i try to catch yellow coin the debug wont show... (i havent slept now huhhu)
wait nvm my dumb brain just connected whats wrong with it, i accidently put at wrong object. script.
So I have just created a power up system but now the enemies don't take any damage until after the sixth shot. I am unknow why this issue is having as the console says the damage amount is 10 but the health doesn't drop.
code
Yeah, but nothing in it should do such a thing and the question is why it last only after six shot. Why would nothing happen till 6 shots after?
Could a static int do such a thing?
post the codes
!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/, https://scriptbin.xyz/
📃 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.
watch the video and look at your hierarchy
What about it?
how do I make HingeJoint2D not limit the object's position but only the rotation?
so like the other object can move as far away as it wants but it needs to stay within the rotation
I remember reading somewhere that you can do that
You've 2 enemies in it, but one is being destroyed which isnt the one you're targeting. Anyway, FindObjectOfType and any Find method is pretty awful and I suggest avoiding them if you can unless you know what you're doing.
yeah find object of type in a collision enter, chances are you are doing something very wrong
Ideally if you want to use a Find type of method, make sure you're using something part of the local hiearchy and not the scene. Something like:
GetComponentInChildren
your just not targeting the right health object, since you are just searching the whole scene for hte first one it finds, not the one on the object collider with
if you are looking for the Health component on the thing the projectile collided with, do other.collider.GetComponent<Health>()
I see, but why didn't do this before?
no clue what you had going on before, but FindObjectOfType is not what you want
Fair, thank you
maybe you only had 1 enemy in the scene before
No, I had mutpile
or just hit a false positive and were always shooting at the first one found by find object of type
I got very lucky
I found useConnectedAnchor for Unity 6000, but I'm on Unity 2020.3. Does anyone know any fix for that version?
anyone online
show your EnemySpawner class
Share the relevant code.
!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/, https://scriptbin.xyz/
📃 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.
As for this screenshot, it's not clear what "this bug" is
A tool for sharing your source code with the world!
oh yea its also making my game lag very badly to a point where it crashes as soon as i run it
just FYI, when pasting code into a paste site you do not include the inline code formatting
is there perhaps more to the stack trace below what was included in the screenshot?
nah its all the same
i'm not asking if the other errors are different, i'm asking if there are more lines in the stack trace
Are you sure that's the correct code?
show where you actually invoke the onEnemyDestroy event
yea its enemy spawner script
this?
private void EnemyDestroyed() {
enemiesAlive--;
CheckWinCondition();
}
no, that is the method subscribed to the event, where do you actually invoke the event
oh i dont think i invoked it anywhere
you clearly have
The callstack implies that the event is invoked in that callback itself.
Was it maybe previous code and you have compile errors now?
pro tip: use your IDE to tell you where you are accessing that variable, you can right click it and find usages
is it this part?
is that the only place it is being used? also this feels like unconfigured vs code
yep
you're telling me that variable is being accessed nowhere else in the code base at all?
and by "that variable" i am, of course, referring to EnemySpawner.onEnemyDestroy
should i move that variable to the health script?
why?
what you need to focus on doing right now is finding where you are using that variable
and if vs code is currently not able to tell you all of the locations you are using that variable in, and more importantly if it doesn't currently show errors in the code or provide autocomplete for unity types then it needs to be configured 👇 !IDE
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
•
Visual Studio (Installed via Unity Hub)
•
Visual Studio (Installed manually)
•
VS Code
•
JetBrains Rider
• :question: Other/None
no idea why you've decided to open that window let alone screenshot it
wdym "its the opening"
why have you even opened that window? what instruction told you to go there
there are two things wrong with this:
- nowhere in that page does it say to check for unity editor updates using the in-editor window
- you are using vs code not visual studio so that's not even the correct configuration steps, unless you've decided to install visual studio and use that instead (which is a good option as it is typically better than vs code)
are we only looking for the EnemySpanwer.onEnemyDestroy specific variable?
yes, you need to find all usages of that variable. but do so after you have configured your code editor
does this part count as one?
private void Awake() {
onEnemyDestroy.AddListener(EnemyDestroyed);
}
have you configured vs code yet
yep
screenshot the entire window then
is this it?
well that is certainly the entire window, but it is also unconfigured.
go through the information on this page if following the correct instructions did not work for you (and no, the instructions for visual studio are not the correct ones as visual studio is a completely separate program from vs code) https://unity.huh.how/ide-configuration/visual-studio-code
does install this reinstall the whole app again?
no
just the vs code?
it does not reinstall anything, it is an extension for vs code so it only installs that extension and its dependencies
is this it?
did you know that typically things that are red with a circled X in them means something is wrong
Can someone show me a video that shows how to create a area where enemies can spawn only within that space?
why is .NET taking so long to install
Tried looking it up but all I get is video on spawning them. Not contanting that spawn to a area that can be shrinked or grow within the engine and not the code
ask ai?
nope nbm
Ask AI
Ai is how I had bad coding to begin with
well yea u need to specify what u want and if u want to modify a code u have to paste the code to it and tell it to modify it the way u want
search:
- how to get a random position in area
- how to spawn enemy/prefab
then combine the two.. maybe a:
- how to chose a random position in area
It also entirely depends on what you define an area to be. Within a range? Within a box? Within an area that can be literally any shape?
guess ai still sucks?
hi I'm trying to edit text which has been working perfectly but today I opened my project and suddenly the box to edit text isn't showing up does anyone know why this is happening?
there could be a ton of reasons why, start debugging and find out why
Which box?
Is this something in editor or in your project?
Well I want a dynamic one cause that follows the player and won't allow the enemy's to fall off the edge
does .NET SDK work with visual studios code?
Yeah
- Do a static one first
- Make sure it adjusts to environment changes, making it dynamic
- profit?

If you have a more specific question, it might be easier to help you.
!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/, https://scriptbin.xyz/
📃 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.
So I watched some video and got ideas but i'm unsure how to put this in. So I want to take the MinSpawn and the maxSpawn to use those to put a full area where they can spawn. But I want to do a check to make sure it's a certain distance from the middle (Aka the player). How would do that?
Do you want them to spawn in a random area in an annulus or something?
A square not a ciricle
So a square ring/annulus?
Oh, just realized what you meant. Yeah, would it be smart then to have three point for that?
Three point?
I'm using raycast to find out if an object is above a tile in my project. However, when I try to detect if there is an object, it will always return false. Even if there is an object above a tile, it will return what is beneath it instead. The object is directly above the tile and the raycast position is directly above the object. Does anyone know why this happens?
How to get the proper position of an UI element in runtime? (In order to return the element back to its place?)
originalPosition = GetComponent<RectTransform>().position;
Behaves badly in my case
If I set the recttransform position again, it goes partially off-screen
At least in some screen sizes
RectTransforms are positioned using anchoredPosition
Thanks
Need some more details on your setup. How far is the raycast origin point from the tile that you want to hit? Is it a 3d raycast and a 3d tile? Does it have a 3d collider? Are you using layermasks?
I have the raycast origin point positioned 5f above the tile that i want to hit. It is a 3d raycast and a 3d plane. Both the object and the plane have 3d colliders. I don't know what layermasks are so probably no.
Did you try drawing debug rays?
The debug rays don't show up even if I put it in Update().
Is that update even executed?
Try adding a log alongside.
The update and the script is executed. Debug.Log() also does not log when placed in the raycast method.
Then it's not executed.
Share the relevant script
However if I debug.log a variable from that method from outside the method it returns the right thing.
That sentence doesn't make sense to me. Share the code.
Where do I paste the 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/, https://scriptbin.xyz/
📃 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.
A tool for sharing your source code with the world!
- This is not update.
- This is not how we start coroutines.
A tool for sharing your source code with the world!
This is the full script
The update calls coroutine Cannon() which would call PieceBelow(PieceBelowi.transform.position, PieceBelowi)
Why is HandleRayCast a Coroutine? Are you expecting it to block Update until it finishes? I'm very confused on what the point is
Also just generally calling a Coroutine in Update is questionable, but in this case it doesn't do anything
HandleRayCast checks where the player is moving their mouse and what it touches in the game.
But why is it a Coroutine?
Well I need it to be a coroutine to check where the player is moving their mouse and what it touches.
For a single frame?
An update method runs every frame, just doing this in a function has the same result
Then it's not called. Put logs all the way through, or step through with a debugger.
But I digress, this is not part of the issue
But it is called because when I use Debug.Log(hoveringTile2); right below line 533, it calls the correct thing.
And how do I use debugger?
Can't see line numbers on mobile.
Keep all the debugs when sharing your code.
Google how to use visual studio debugger with unity.
Does paste.mod even work on mobile? The second I scroll down it, the entire page goes blank
It is Debug.Log(hoveringTile2 + '|' + PieceBelowi.name);
Works if you press the </> button
Debug.Log($"{hoveringTile2} | {PieceBelowi.name}"); for what it's worth, string interpolation is a far nicer way to write string like this
I did not know I could do that
I have about 3-4 weeks experience on Unity and C# code.
It's something I wish I'd known earlier
So, as I said earlier, you're not starting a coroutine correctly
How do I start a coroutine correctly?
With StartCoroutine
But I did start it with StartCoroutine in Update();
But you don't start it properly where you debug.
So it's not called correctly from there.
Honestly, I'd tear it all down and rewrite it with less coroutines.
Oh wait no I see.
But is it possible for PieceBelow to be a method not a coroutine; using void not IEnumerator?
I have less than a week to create a functioning game, I don't want to do this.
It can be a method, sure. Just don't declare it as a coroutine and don't yield inside.
Ok
But how do I solve this?
Make the method be executed correctly obviously.
That's what we're fixing, don't we?
But How do I do this?
Either start the coroutine correctly or rewrite it into a normal method...
I changed it into a normal method.
Yet Debug.Log(piecebelowi) still returns the tile below the gameobject.
Are there any reasons why a raycast may be ignoring an object?
What about the debug ray?
I feel like you're half ignoring what I'm saying...
I used debug.drawray before but it didn't show the ray.
Before, the raycast and the debug ray were not executing though, right? Because you didn't start the coroutine correctly.
Does it draw now that you changed it to a normal method?
Do I place the drawray inside the raycast method?
I tried it in both and it still does not show up in game view or scene view
Alongside it, yes.
Then either the position/direction is wrong, or the code is not executed. Did you add a log there as well?
I added a log in both raycast method and the coroutine the method appears in
Great!
So does it log?
No
This happens when I make an illegal move. 7, 7|7, 7 is a concatenation of hoveringTile2, which is initialised in the raycast method. 7, 7 is also the name of the tile which is below the rightmost piece called Cannon. moved? comes from the MovePiece method which I need to code to move the piece to the position.
Where's a log that's after the raycast line?
A tool for sharing your source code with the world!
Make your logs more verbose. It's not clear what the message implies and where it comes from..
I don't see a single debug logs here:
void PieceBelow(Vector3 tilePosition, GameObject tile)
{
Vector3 offset = new Vector3(0f, 5f, 0f);
Vector3 aboveTile = tilePosition + offset;
ray2 = new Ray(aboveTile, Vector3.down);
if (Physics.Raycast(ray2, out hit2))
{
hoveringTile2 = hit2.transform.name;
if (hoveringTile2 == tile.name)
spaceOccupied = false;
else
spaceOccupied = true;
}
Debug.DrawRay(aboveTile, Vector3.down, Color.yellow);
return;
}
Am I blind or are you still ignoring half of what I'm saying?
Btw, you don't need a return at the end. It does absolutely nothing
Oh Debug.Log, I did Debug.DrawRay
A tool for sharing your source code with the world!
It logs the position of aboveTile
But it still ignores the object.
Make your logs more verbose.
Debug.Log("Raycasting at pos: {position}");
Or something like that.
Once you do, take a screenshot of the console showing that the log is printed
that wouldn't work right?
need the $ before the first "?
right.
Take a screenshot of the log showing up in the console
Great. Now let's find your debug ray. Check the debug ray docs. It has a parameter to define how long it would be drawn. Set it to something like 60 sec.
What are the debug ray docs?
Oh parameters
I did this: Debug.DrawRay(aboveTile, Vector3.down, Color.yellow, 60f);
Now look around in the scene view
Btw I am using Unity 2022.3
Doesn't matter
Check the method documentation. it says something about ray length
Only Physics.RayCast can change maxlength.
A tool for sharing your source code with the world!
So I set it to 10f.
It still only goes halfway.
Nevermind it works
A tool for sharing your source code with the world!
Ok, so does it cross the object with a collider?
The object still does not.
Does the debug ray cross the object you expect it to collide with?
Ok, take a screenshot of the object selected with collider gizmos visible.
Does the ray start outside the collider?
So it was srarting inside the collider?
I changed it so it was starting outside the collider
Then what was the problem?
I guess that was the problem
from what i can tell you are using raycasts for selecting a tile? better to use the pointer events + event system if you can as its much more reliable @lone tundra
can be used with 3d and 2d physics to easily do click detection and other things.
I am using raycasts to check if there is anyting above the tile.
anything like that should doable in logic (e.g. each tile has a field to hold what is "above it" or you have a 2d grid of layers and you can find whats at this position in the layer above)
using physics for tasks that can be done at a lower level is not wise
I wasn't sure how to do that so I used rays because I've heard of it before.
You can have a list of 2d arrays to create layers of grids (List<Tile[,]> tileLayers) or just have a public field/property on the tile you assign the thing above it to.
can also just do grids as 1D arrays its pretty simple math to go from 2d coord to index if you know the width
easier to serialize
Does anyone know a model i can use to identify two difference peoples voices, and then tell me, which person is talking into the mic on unity. been trying to figure this out using sentis, and importing models, but i just cant get it to work, and i cant find anyone who has done it before.
yea thats true but 2d arrays are simpler for beginners to access elements. I also prefer 1d
yeah just mentioning find 1d is just nicer expecially once you have to save it
worth keeping in mind this won't serialize right?
it would not
doesnt need to. can be build at runtime if the position is set on each mono instance
it can not need to ye but just worth mentioning in case person decides to store it another way
you could easily have a List of struct where the struct has a 1d array and that would serialize just fine
or if you have a defined amount of layers just have the layers be top level
if you have even a semi large grid, making the array in inspector correctly wont be easy so I would not go this route.
Games I work on with 2d grids dont serialize any of this
there's many solutions forsure im just acknowledging that the problem does exist because it can easily trip people up
its not about editing in the array inspector for some though, at my old job we serialized stuff to SO's and it was not visible in inspector but only modifed via our own tooling
just depends
well this is past beginner stuff so then you can do whatever you want
it was required since each placeable object had grid data it needed to write to the main games grid so had a editor for that
was just letting unity do the serialization early on in dev, then once the structure for each tile was well defined changed to a custom binary format
in 3d what's usually done to make multiple objects be the exact same distance between each other (like houses for ex.)
you can set the position to be whatever you want it to be
is there something more specific you need than adding the distance from the last object position?
Hi, I'm creating a Tarot Chess game, in which you play chess with many magical effects. Today I'm working on The World, which basically works like a border, shrinking the board from 8x8 to 6x6 to 4x4 to 2x2. I have this covered, but now I want to some visual effects. I decided on particle system 'fog'. The problem is, that the fog needs to be dense, so it almost covers the entire unplayable squares, and it also cannot emit particles on the playable chess tiles. Any idea how to do that?
The world image vs what i did
using UnityEngine;
using UnityEngine.EventSystems;
public class Dialogue : MonoBehaviour, IPointerClickHandler
{
public GameObject dialogueBox;
public string dialogueText;
public Texture[] portraitTextures;
public void OnPointerClick(PointerEventData eventData)
{
dialogueBox.SetActive(true);
if (DialogueManager.Instance != null)
{
DialogueManager.Instance.DisplayDialogue(dialogueText, portraitTextures);
}
else
{
Debug.LogError("DialogueManager.Instance is null");
}
}
public void OnBeginDrag(PointerEventData eventData)
{
dialogueBox.SetActive(true);
if (DialogueManager.Instance != null)
{
DialogueManager.Instance.DisplayDialogue(dialogueText, portraitTextures);
}
else
{
Debug.LogError("DialogueManager.Instance is null");
}
}
}
OnPointerClick does what I want, but OnBeginDrag doesn't respond. Any ideas why?
im not really sure what that first image has to do with anything, looks ai generated tbh. this also doesnt look like a coding question either, probably #✨┃vfx-and-particles
You are missing , IBeginDragHandler
Silly me, that was the issue so it works now. It's odd that it didn't give a error nor red underline.
Thanks!
I don't think this is a codeable solution, I think this is more of a #✨┃vfx-and-particles question. As to preventing the "live" squares from being occluded, you could put a collider over the whole playable area on a layer that only the particles interact with, and have those particles destroy themselves on collision
Well, it's not a compile error. You can freely define a function named OnBeginDrag in any script you'd like. It just won't be overriding anything unless you have that interface implemented
Ah, that makes sense.
It was for reference. Yes, it is AI generated, as for now I can't afford that much input from real artists, so I pay only for what I have to. I plan to change it in the future
Ok, I didn't know you can destroy on collision (it makes sense now that I think about it lol), I'll try
i need help guys
Same answer to your previous statement:
i can't explain this one
Then please don't spam here, thanks.
i need someone to join with me in a voie chat
Not how this server works.
If you can't explain it in text, you can't explain it in voice. If you can't ask your question, then please don't spam.
Screenshots and/or some code are a good start
the code has no errors, but the outcome isn't forming in the way i wanted
well you said so , though i can screenshare
So then you should actually ask a question
There is no voice chat or screen sharing here. If you will not put in the effort to even form your question into words, why would you expect someone to put in the effort to jump into a call they have no idea if they can even solve
paste your code here, let us know what you want it to do, and what it's actually doing 🙂
!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/, https://scriptbin.xyz/
📃 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.
public class ObjectBehaviour : MonoBehaviour
{
[SerializeField]GameObject _prefab;
[SerializeField] private bool _gameOver = true;
public void spawnObject()
{
Instantiate(_prefab, new Vector3(Random.Range(-8f, 8f), 6f, 0f), Quaternion.identity);
}
private void OnCollisionEnter2D(Collision2D collision)
{
if(collision.gameObject.tag =="Player" && !_gameOver)
{
Debug.Log("Touched");
spawnObject();
Destroy(gameObject);
}
else if (collision.gameObject.tag =="Ground")
{
_gameOver = false;
Debug.Log("GAME OVER , YOU'VE LOST");
}
}
}```
Okay, so what is the issue
class Test : MonoBehaviour // Inheriting class (child class)
{
[SerializeField] ObjectBehaviour Block;
[SerializeField]private float _playerSpeed = 5f;
private Rigidbody2D _rigidbody;
float _inputHor;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
_rigidbody = gameObject.GetComponent<Rigidbody2D>();//syncing
Block.spawnObject();
}
// Update is called once per frame
void Update()
{
_inputHor = Input.GetAxisRaw("Horizontal");
if (_inputHor != 0)
{
_rigidbody.AddForce(new Vector2((_inputHor * _playerSpeed),0f));
}
}
}```
The second script is the most important to me. In it, when the player object touches another object, a "Next" object is supposed to spawn. However, I’m facing an issue: when I start the game, the first object spawns as expected, but when the player touches it, nothing happens. Please help me fix this.
What object have you set for Block
a square
You need to debug your OnCollisionEnter2D code
In the scene, or a prefab
use Debug.Log statements to check that it's running as expected and that the data is as you expect
i did , but when starting the game , the code written won't work on the first spawned "block"
"won't work" is not useful
Put a log outside the if statements
yea a square sprite
you need to take concrete debugging steps and show the results
In the scene, or a prefab
you mean the name of the object?
What do you think is the best path to take to learn unity c# programming with unity learn?
No I mean the object
is the object in the scene, or a prefab
a prefab
Yeah, that's your issue. You need to assign the in-scene object to the Block variable
I don't see why that variable exists at all to be perfectly honest
AFAICT this whole interaction is supposed to be happening when the objects collide
so the focus here should be OnCollisionEnter2D
the Start() code is a red herring I think
Yeah, I'm assuming the _prefab variable on the block is a different object, otherwise, why would you be calling the function from this object instead of just spawning it in Test?
If the intention is to spawn an ObjectBehaviour, why would you call a function on an object behaviour to do so?
Looks like it's a game where you need to catch items in a bucket
So the _prefab variable would be a reference to its own prefab. Once the object is caught in the bucket, it spawns a new version of itself at a random position in the air
And if it hits the ground, it calls a game over
exactly
So there's a few issues with your code you'll need to fix
First, move the OnCollisionEnter to the Test script, and give the block prefab a tag to test against. Ideally you'll eventually want to move towards a game manager that handles creating these items and evaluating game state, but you're not quite at that level yet
Also have the game over be stored in the player. Every time you create a block, it has its own internal Game Over state that doesn't persist past the block's destruction
The only thing your block should need to worry about is if it's hit the ground
Depending on how questionable you want your coding practices to be, I'd recommend a third script called "GameManager" or something like that, and give it some static functions and variables so anything can easily talk to it
Then, for example, if the block hits the ground, it can just call "GameManager.GameOver()" and that'll handle everything
OnCollisionEnter is a private method
and i could change it to public but an error poped out to me
This got missed in the above discussion.
Best path is probably not to use Unity Learn
That's not relevant
oh... uhm... I ended now the "unity essentials" but I think it was the last thing to do
What's your level of C# experience?
Zero experience
You're about to enter a world of wonderment 🙂
Any experience with other coding languages?
lol, all good
The pins in this channel should help
Start here I suppose
https://learn.unity.com/pathway/unity-essentials/unit/programming-essentials
Free tutorials, courses, and guided pathways for mastering real-time 3D development skills to make video games, VR, AR, and more.
Youtube is usually pretty effective for general C#. The hardest part is learning how to think in terms of logic, and break your problems down into steps
true
look at the pins, there is a link for intro to c#
yeah but I started from beginner scripting but it's not a good start I think
(note that the intro to c# tutorials won't work in Unity. You'll need to run them in Visual Studio directly)
kk, i moved the question to #✨┃vfx-and-particles and tried your way
it teaches you hello world, loops, and if statements. its about as beginner as you can be.
yup I downloaded it
Cool cool. Leave Unity alone for a little bit then and work through some C# tutorials
Once you know the absolute basics as bawsi mentioned, come back and learn how to apply them to Unity
Thank you 🙂
No worries! Good luck 🙂
how can i make mods for games
i wanna make just a small mod for schedule 1 but all it is that i just dont know how to mod games
modding discussions are not permitted here #📖┃code-of-conduct
find the modding community for the game you are interested in modding and learn from them
okay thank you
heyyy uhm, im working on a project and im trying to get an object to move an a parabolic shape. though, when i try and write the code for it it says "MathParabola" doesen't exist, am i being stupid or uh..
(yes, i have the mathematics package)
What is MathParabola?
That's not somthing in Unity.Mathematics afaik
i couldve sworn it was unless my brain is playing tricks on me
uh, how do i do what im doing then 
Step one is to look it up in the docs
Step 2 is to google it which brought this up for me, maybe you mean this custom package? https://github.com/nkpark/Unity3D-MathParabola
Option 3 is just to do the math yourself
parabolas are well defined
Option 4 is use an animation curve
thatd probably be easier but
i dont know how id put the math into unity
you'd use a parameteric equation for the parabola
so you can plug in t and get out x and y
okayyy.. ill try but idk ill be able
Asking ChatGPT "What are the parametric equations for a parabola" and going from there would get you pretty far. T is time.
no no i know the equations just im a math whiz not a programming whiz lol
once you have a parametric equation it's very straightforward
you just plug the equation into the code more or less
they let you calculate the x and y position at a given time
then you just use that to position your object
myObject.position = new Vector3(x, y);
Your Animation variable from your code snippet above
is tracking elapsed time
that would be t
make sense?
let me get that code back lmao
yeah
im lying im still confused on how to go about this but im trying
Basically:
- increment your timer (t) as you already were doing.
- Plug t into each of the parametric equations for the parabola. One of them calculates X, one calculates Y.
- Use the calculated X and Y to position the object
Hey i need really some help. I've been stuck on the same problem since 3 Weeks and don't know how to get rid of. So my Character cant jump and i don't know why. If i thinks its because of some Ground check problem but i don't really know. (and yes the code was written by ChatGpt because it doesnt work when i do it.)
you also haven't set up your layer mask
and need to configure vs code 👇 !IDE
That error in the console is likely because you have a second copy of the PlayerMovement script on some object in the scene where you didn't assign that variable
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
See how this says Nothing
that means it's not going to detect anything
and you will never be able to jump
okay so kinda like this? or
Oh… wait ill change that
The y equation doesn't look right, no
x shouldn't be a parameter
t should be appearing in there
yeah that looks more right
okay..
also whys it think my position is weird
Did you read the error message?
It will tell you what's wrong
My guess is that Fish is not a Transform
the screenshot above is the same math as the one further above, unless you're referring to something else
it has x inside Pow instead of Animation
I see that he's factoring in x * 2
so it's the same yeah
but conceptually wrong
so to which one should i change it?
to whichever layer your ground is on
most likely youi should create a special layer for thje ground
and put the ground on that layer
So i did all of that. Still shows that something is wrong😭
Find and delete the extra copy of the script
So the Error went away, but my Character still cant Jump. I think it rather lies in the code?
Check if isGrounded is true when you expect it to be
why did you put the player on the Ground layer?
IDK😭 . To which one should i put it
not the ground
only the ground should be on the ground layer
so should i let it on Default
sure
ill try and see if he jumps. If he doesn't then i think it has to do with something in the code
more likely your force is just not big enough
or your ground check object is in the wrong position
or the ground is missing the ground layer
you should be debugging your code with Debug.Log to find out which
My ground is false. What should i do?
can you paste image of code with debug statement
check where your ground check object is
and also check that the ground has the appropriate layer as mentioned before
0.1 might be a radius too small. What does your player's collider look like?
the player collider is also not relevant to this
so my Groundcheck is right next to my character. Should i put under him?
try setting the 0.2f radius to something really large and have the jump force be really high and see if he jumps just to test where the problem is
what do you think?
yes thats the problem
what would make sense
under him?
that is where the 0.2f comes from. so if it's not low enough it wont detect the ground
IT FINALLY WORKS. Thanks yall❤️
It would certainly be weird if someone's feet were only on the ground if there was something solid hovering a foot behind their right shoulder
The only problem now is the Double jumps
make sure he can only j ump when isGrounded is true
im having a bit of a similar problem now
im trying to make jumping, and i have it working apart from the fact that "speed" affects "y" which in turn m akes it so if im sprinting, i can jump super high
So don't multiply the Y by speed
Get the horizontal vectors, multiply them by speed, then add the vertical vector
Then move that ammount
like this?
Yeah, or just multiply it by speed in the assignment to movement
How do you setup xbox controller? Thought it was this but nada
okay so basically i ran it and
i was running insanely fast, and was falling insanely slow
(i already tried what you suggested earlier just thought id try it again)
Well, because you were always multiplying by speed before. You're going to need to increase some of the values now that it's no longer dependent on speed
If you're doing gamepad bindings, you really should consider using the new input system. It makes dealing with them significantly easier.
I know
It's more complex for super basic things like detecting a single key press but makes different controller bindings basically trivial
If this was my personal project yea
But we just had to find opensource project and modify it
So I'm just using what they had setup.
I was going off this image
increase?
sorry im not following
If your speed was 10, and your Y movement was 1, before you were moving by 10 units per second. If your speed increased to 20, you'd be moving up at 20 units per second. This is not what you want.
Now, speed is no longer a factor. If your Y movement is 1, you're moving at 1 unit per second, which is less than 10
So whatever numbers you were using to calculate y are now giving you a smaller result than before
i know how to do that just the problem is
i am now moving at insane speeds
like x and z values
like, accross the whole map in 0.01 seconds fast
Are you still remembering to multiply your horizontal speed by deltaTime
Got part of it
So, no
https://paste.mod.gg/czfgabkifdmr/0 Hi i can't seem to change the color of my text. it says it has in the debug not not on game mode
A tool for sharing your source code with the world!
